Package org.apache.tomcat.util.threads
Class ThreadPoolExecutor
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- org.apache.tomcat.util.threads.ThreadPoolExecutor
-
- All Implemented Interfaces:
java.util.concurrent.Executor,java.util.concurrent.ExecutorService
public class ThreadPoolExecutor extends java.util.concurrent.ThreadPoolExecutorSame as a java.util.concurrent.ThreadPoolExecutor but implements a much more efficientgetSubmittedCount()method, to be used to properly handle the work queue. If a RejectedExecutionHandler is not specified a default one will be configured and that one will always throw a RejectedExecutionException
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
java.util.concurrent.ThreadPoolExecutor.AbortPolicy, java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardPolicy
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringManagersmThe string manager for this package.
-
Constructor Summary
Constructors Constructor Description ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue)ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue, java.util.concurrent.RejectedExecutionHandler handler)ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue, java.util.concurrent.ThreadFactory threadFactory)ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue, java.util.concurrent.ThreadFactory threadFactory, java.util.concurrent.RejectedExecutionHandler handler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafterExecute(java.lang.Runnable r, java.lang.Throwable t)voidcontextStopping()protected booleancurrentThreadShouldBeStopped()voidexecute(java.lang.Runnable command)voidexecute(java.lang.Runnable command, long timeout, java.util.concurrent.TimeUnit unit)Executes the given command at some time in the future.intgetSubmittedCount()longgetThreadRenewalDelay()voidsetThreadRenewalDelay(long threadRenewalDelay)protected voidstopCurrentThreadIfNeeded()If the current thread was started before the last time when a context was stopped, an exception is thrown so that the current thread is stopped.-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toString
-
-
-
-
Field Detail
-
sm
protected static final StringManager sm
The string manager for this package.
-
-
Constructor Detail
-
ThreadPoolExecutor
public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue, java.util.concurrent.RejectedExecutionHandler handler)
-
ThreadPoolExecutor
public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue, java.util.concurrent.ThreadFactory threadFactory, java.util.concurrent.RejectedExecutionHandler handler)
-
ThreadPoolExecutor
public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue, java.util.concurrent.ThreadFactory threadFactory)
-
ThreadPoolExecutor
public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue)
-
-
Method Detail
-
getThreadRenewalDelay
public long getThreadRenewalDelay()
-
setThreadRenewalDelay
public void setThreadRenewalDelay(long threadRenewalDelay)
-
afterExecute
protected void afterExecute(java.lang.Runnable r, java.lang.Throwable t)- Overrides:
afterExecutein classjava.util.concurrent.ThreadPoolExecutor
-
stopCurrentThreadIfNeeded
protected void stopCurrentThreadIfNeeded()
If the current thread was started before the last time when a context was stopped, an exception is thrown so that the current thread is stopped.
-
currentThreadShouldBeStopped
protected boolean currentThreadShouldBeStopped()
-
getSubmittedCount
public int getSubmittedCount()
-
execute
public void execute(java.lang.Runnable command)
- Specified by:
executein interfacejava.util.concurrent.Executor- Overrides:
executein classjava.util.concurrent.ThreadPoolExecutor
-
execute
public void execute(java.lang.Runnable command, long timeout, java.util.concurrent.TimeUnit unit)Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of theExecutorimplementation. If no threads are available, it will be added to the work queue. If the work queue is full, the system will wait for the specified time and it throw a RejectedExecutionException if the queue is still full after that.- Parameters:
command- the runnable tasktimeout- A timeout for the completion of the taskunit- The timeout time unit- Throws:
java.util.concurrent.RejectedExecutionException- if this task cannot be accepted for execution - the queue is fulljava.lang.NullPointerException- if command or unit is null
-
contextStopping
public void contextStopping()
-
-