Class StandardThreadExecutor
java.lang.Object
org.apache.catalina.util.LifecycleBase
org.apache.catalina.util.LifecycleMBeanBase
org.apache.catalina.core.StandardThreadExecutor
- All Implemented Interfaces:
AutoCloseable, Executor, ExecutorService, MBeanRegistration, Executor, JmxEnabled, Lifecycle, ResizableExecutor
public class StandardThreadExecutor
extends LifecycleMBeanBase
implements Executor, ResizableExecutor
Standard implementation of an
Executor based on a Java thread pool.-
Nested Class Summary
Nested classes/interfaces inherited from interface Lifecycle
Lifecycle.SingleUse -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanRun threads in daemon or non-daemon stateprotected ThreadPoolExecutorThe executor we use for this componentprotected intidle time in millisecondsprotected intThe maximum number of elements that can queue up before we reject themprotected intmax number of threadsprotected intmin number of threadsprotected Stringthe name of this thread poolprotected StringDefault name prefix for the thread nameprotected static final StringManagerStringManager for this package.protected intDefault thread priorityprotected longAfter a context is stopped, threads in the pool are renewed.Fields inherited from interface Lifecycle
AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitTermination(long timeout, TimeUnit unit) voidNotify the underlying executor that the associated context is stopping so that it can prepare for shutdown.voidintReturns the approximate number of threads that are actively executing tasks.longReturn the approximate total number of tasks that have completed execution.intReturn the core number of threads for the underlying thread pool.protected StringMethod implemented by subclasses to identify the domain in which MBeans should be registered.intReturn the largest number of threads that have ever simultaneously been in the pool.intReturn the maximum idle time in milliseconds.intReturn the maximum number of elements that can queue up before tasks are rejected.intReturns the maximum number of threads in the pool.intReturn the minimum number of spare threads.getName()Returns the name of this executor.Return the name prefix for new threads.protected StringAllow subclasses to specify the key properties component of theObjectNamethat will be used to register this component.intReturns the current number of threads in the pool.intReturn the current queue size.intReturn the thread priority for new threads.longReturn the thread renewal delay in milliseconds.invokeAll(Collection<? extends Callable<T>> tasks) invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) <T> TinvokeAny(Collection<? extends Callable<T>> tasks) <T> TinvokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) booleanisDaemon()Return whether threads are daemon threads.booleanbooleanbooleanresizePool(int corePoolSize, int maximumPoolSize) Resize the thread pool.booleanresizeQueue(int capacity) Resize the work queue.voidsetDaemon(boolean daemon) Set whether threads are daemon threads.voidsetMaxIdleTime(int maxIdleTime) Set the maximum idle time in milliseconds.voidsetMaxQueueSize(int size) Set the maximum queue size.voidsetMaxThreads(int maxThreads) Set the maximum number of threads in the pool.voidsetMinSpareThreads(int minSpareThreads) Set the minimum number of spare threads.voidSet the name for this executor.voidsetNamePrefix(String namePrefix) Set the name prefix for new threads.voidsetThreadPriority(int threadPriority) Set the thread priority for new threads.voidsetThreadRenewalDelay(long threadRenewalDelay) Set the thread renewal delay in milliseconds.voidshutdown()protected voidStart the component and implement the requirements ofLifecycleBase.startInternal().protected voidStop the component and implement the requirements ofLifecycleBase.stopInternal().Future<?> <T> Future<T> <T> Future<T> Methods inherited from class LifecycleMBeanBase
destroyInternal, getDomain, getObjectName, initInternal, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregisterMethods inherited from class LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stopMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ExecutorService
closeMethods inherited from interface Lifecycle
addLifecycleListener, destroy, findLifecycleListeners, getState, getStateName, init, removeLifecycleListener, start, stop
-
Field Details
-
sm
StringManager for this package. -
threadPriority
protected int threadPriorityDefault thread priority -
daemon
protected boolean daemonRun threads in daemon or non-daemon state -
namePrefix
Default name prefix for the thread name -
maxThreads
protected int maxThreadsmax number of threads -
minSpareThreads
protected int minSpareThreadsmin number of threads -
maxIdleTime
protected int maxIdleTimeidle time in milliseconds -
executor
The executor we use for this component -
name
the name of this thread pool -
maxQueueSize
protected int maxQueueSizeThe maximum number of elements that can queue up before we reject them -
threadRenewalDelay
protected long threadRenewalDelayAfter a context is stopped, threads in the pool are renewed. To avoid renewing all threads at the same time, this delay is observed between 2 threads being renewed.
-
-
Constructor Details
-
StandardThreadExecutor
public StandardThreadExecutor()Default constructor required for the Digester.
-
-
Method Details
-
startInternal
Start the component and implement the requirements ofLifecycleBase.startInternal().- Specified by:
startInternalin classLifecycleBase- Throws:
LifecycleException- if this component detects a fatal error that prevents this component from being used
-
stopInternal
Stop the component and implement the requirements ofLifecycleBase.stopInternal().- Specified by:
stopInternalin classLifecycleBase- Throws:
LifecycleException- if this component detects a fatal error that needs to be reported
-
execute
-
contextStopping
public void contextStopping()Notify the underlying executor that the associated context is stopping so that it can prepare for shutdown. -
getThreadPriority
public int getThreadPriority()Return the thread priority for new threads.- Returns:
- the thread priority
-
isDaemon
public boolean isDaemon()Return whether threads are daemon threads.- Returns:
- true if threads are daemon threads
-
getNamePrefix
-
getMaxIdleTime
public int getMaxIdleTime()Return the maximum idle time in milliseconds.- Returns:
- the maximum idle time in milliseconds
-
getMaxThreads
public int getMaxThreads()Description copied from interface:ResizableExecutorReturns the maximum number of threads in the pool.- Specified by:
getMaxThreadsin interfaceResizableExecutor- Returns:
- the maximum number of threads
-
getMinSpareThreads
public int getMinSpareThreads()Return the minimum number of spare threads.- Returns:
- the minimum spare threads
-
getName
-
setThreadPriority
public void setThreadPriority(int threadPriority) Set the thread priority for new threads.- Parameters:
threadPriority- the thread priority
-
setDaemon
public void setDaemon(boolean daemon) Set whether threads are daemon threads.- Parameters:
daemon- true for daemon threads
-
setNamePrefix
Set the name prefix for new threads.- Parameters:
namePrefix- the name prefix
-
setMaxIdleTime
public void setMaxIdleTime(int maxIdleTime) Set the maximum idle time in milliseconds.- Parameters:
maxIdleTime- the maximum idle time
-
setMaxThreads
public void setMaxThreads(int maxThreads) Set the maximum number of threads in the pool.- Parameters:
maxThreads- the maximum threads
-
setMinSpareThreads
public void setMinSpareThreads(int minSpareThreads) Set the minimum number of spare threads.- Parameters:
minSpareThreads- the minimum spare threads
-
setName
Set the name for this executor.- Parameters:
name- the executor name
-
setMaxQueueSize
public void setMaxQueueSize(int size) Set the maximum queue size.- Parameters:
size- the maximum queue size
-
getMaxQueueSize
public int getMaxQueueSize()Return the maximum number of elements that can queue up before tasks are rejected.- Returns:
- the maximum queue size
-
getThreadRenewalDelay
public long getThreadRenewalDelay()Return the thread renewal delay in milliseconds.- Returns:
- the thread renewal delay
-
setThreadRenewalDelay
public void setThreadRenewalDelay(long threadRenewalDelay) Set the thread renewal delay in milliseconds.- Parameters:
threadRenewalDelay- the thread renewal delay
-
getActiveCount
public int getActiveCount()Description copied from interface:ResizableExecutorReturns the approximate number of threads that are actively executing tasks.- Specified by:
getActiveCountin interfaceResizableExecutor- Returns:
- the number of threads
-
getCompletedTaskCount
public long getCompletedTaskCount()Return the approximate total number of tasks that have completed execution.- Returns:
- the completed task count
-
getCorePoolSize
public int getCorePoolSize()Return the core number of threads for the underlying thread pool.- Returns:
- the core pool size
-
getLargestPoolSize
public int getLargestPoolSize()Return the largest number of threads that have ever simultaneously been in the pool.- Returns:
- the largest pool size
-
getPoolSize
public int getPoolSize()Description copied from interface:ResizableExecutorReturns the current number of threads in the pool.- Specified by:
getPoolSizein interfaceResizableExecutor- Returns:
- the number of threads
-
getQueueSize
public int getQueueSize()Return the current queue size.- Returns:
- the queue size, or -1 if not available
-
resizePool
public boolean resizePool(int corePoolSize, int maximumPoolSize) Description copied from interface:ResizableExecutorResize the thread pool.- Specified by:
resizePoolin interfaceResizableExecutor- Parameters:
corePoolSize- The new core pool sizemaximumPoolSize- The new maximum pool size- Returns:
- True if the pool was resized successfully
-
resizeQueue
public boolean resizeQueue(int capacity) Description copied from interface:ResizableExecutorResize the work queue.- Specified by:
resizeQueuein interfaceResizableExecutor- Parameters:
capacity- The new queue capacity- Returns:
- True if the queue was resized successfully
-
getDomainInternal
Description copied from class:LifecycleMBeanBaseMethod implemented by subclasses to identify the domain in which MBeans should be registered.- Specified by:
getDomainInternalin classLifecycleMBeanBase- Returns:
- The name of the domain to use to register MBeans.
-
getObjectNameKeyProperties
Description copied from class:LifecycleMBeanBaseAllow subclasses to specify the key properties component of theObjectNamethat will be used to register this component.- Specified by:
getObjectNameKeyPropertiesin classLifecycleMBeanBase- Returns:
- The string representation of the key properties component of the desired
ObjectName
-
shutdown
public void shutdown()- Specified by:
shutdownin interfaceExecutorService
-
shutdownNow
- Specified by:
shutdownNowin interfaceExecutorService
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdownin interfaceExecutorService
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminatedin interfaceExecutorService
-
awaitTermination
- Specified by:
awaitTerminationin interfaceExecutorService- Throws:
InterruptedException
-
submit
- Specified by:
submitin interfaceExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException - Specified by:
invokeAllin interfaceExecutorService- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException - Specified by:
invokeAllin interfaceExecutorService- Throws:
InterruptedException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException - Specified by:
invokeAnyin interfaceExecutorService- Throws:
InterruptedExceptionExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
invokeAnyin interfaceExecutorService- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-