Package org.apache.catalina.core
Class StandardThreadExecutor
- java.lang.Object
-
- org.apache.catalina.util.LifecycleBase
-
- org.apache.catalina.util.LifecycleMBeanBase
-
- org.apache.catalina.core.StandardThreadExecutor
-
- All Implemented Interfaces:
java.util.concurrent.Executor,java.util.concurrent.ExecutorService,javax.management.MBeanRegistration,Executor,JmxEnabled,Lifecycle,ResizableExecutor
public class StandardThreadExecutor extends LifecycleMBeanBase implements Executor, java.util.concurrent.ExecutorService, ResizableExecutor
Standard implementation of anExecutorbased on a Java thread pool.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.catalina.Lifecycle
Lifecycle.SingleUse
-
-
Field Summary
Fields Modifier and Type Field Description protected booleandaemonRun threads in daemon or non-daemon stateprotected ThreadPoolExecutorexecutorThe executor we use for this componentprotected intmaxIdleTimeidle time in millisecondsprotected intmaxQueueSizeThe maximum number of elements that can queue up before we reject themprotected intmaxThreadsmax number of threadsprotected intminSpareThreadsmin number of threadsprotected java.lang.Stringnamethe name of this thread poolprotected java.lang.StringnamePrefixDefault name prefix for the thread nameprotected static StringManagersmStringManager for this package.protected intthreadPriorityDefault thread priorityprotected longthreadRenewalDelayAfter a context is stopped, threads in the pool are renewed.-
Fields inherited from interface org.apache.catalina.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 Constructor Description StandardThreadExecutor()Default constructor required for the Digester.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanawaitTermination(long timeout, java.util.concurrent.TimeUnit unit)voidcontextStopping()Notify the underlying executor that the associated context is stopping so that it can prepare for shutdown.voidexecute(java.lang.Runnable command)intgetActiveCount()Returns the approximate number of threads that are actively executing tasks.longgetCompletedTaskCount()Return the approximate total number of tasks that have completed execution.intgetCorePoolSize()Return the core number of threads for the underlying thread pool.protected java.lang.StringgetDomainInternal()Method implemented by subclasses to identify the domain in which MBeans should be registered.intgetLargestPoolSize()Return the largest number of threads that have ever simultaneously been in the pool.intgetMaxIdleTime()Return the maximum idle time in milliseconds.intgetMaxQueueSize()Return the maximum number of elements that can queue up before tasks are rejected.intgetMaxThreads()Returns the maximum number of threads in the pool.intgetMinSpareThreads()Return the minimum number of spare threads.java.lang.StringgetName()Returns the name of this executor.java.lang.StringgetNamePrefix()Return the name prefix for new threads.protected java.lang.StringgetObjectNameKeyProperties()Allow subclasses to specify the key properties component of theObjectNamethat will be used to register this component.intgetPoolSize()Returns the current number of threads in the pool.intgetQueueSize()Return the current queue size.intgetThreadPriority()Return the thread priority for new threads.longgetThreadRenewalDelay()Return the thread renewal delay in milliseconds.<T> java.util.List<java.util.concurrent.Future<T>>invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)<T> java.util.List<java.util.concurrent.Future<T>>invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)<T> TinvokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)<T> TinvokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)booleanisDaemon()Return whether threads are daemon threads.booleanisShutdown()booleanisTerminated()booleanresizePool(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.voidsetName(java.lang.String name)Set the name for this executor.voidsetNamePrefix(java.lang.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()java.util.List<java.lang.Runnable>shutdownNow()protected voidstartInternal()Start the component and implement the requirements ofLifecycleBase.startInternal().protected voidstopInternal()Stop the component and implement the requirements ofLifecycleBase.stopInternal().java.util.concurrent.Future<?>submit(java.lang.Runnable task)<T> java.util.concurrent.Future<T>submit(java.lang.Runnable task, T result)<T> java.util.concurrent.Future<T>submit(java.util.concurrent.Callable<T> task)-
Methods inherited from class org.apache.catalina.util.LifecycleMBeanBase
destroyInternal, getDomain, getObjectName, initInternal, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregister
-
Methods inherited from class org.apache.catalina.util.LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.catalina.Lifecycle
addLifecycleListener, destroy, findLifecycleListeners, getState, getStateName, init, removeLifecycleListener, start, stop
-
-
-
-
Field Detail
-
sm
protected static final StringManager sm
StringManager for this package.
-
threadPriority
protected int threadPriority
Default thread priority
-
daemon
protected boolean daemon
Run threads in daemon or non-daemon state
-
namePrefix
protected java.lang.String namePrefix
Default name prefix for the thread name
-
maxThreads
protected int maxThreads
max number of threads
-
minSpareThreads
protected int minSpareThreads
min number of threads
-
maxIdleTime
protected int maxIdleTime
idle time in milliseconds
-
executor
protected ThreadPoolExecutor executor
The executor we use for this component
-
name
protected java.lang.String name
the name of this thread pool
-
maxQueueSize
protected int maxQueueSize
The maximum number of elements that can queue up before we reject them
-
threadRenewalDelay
protected long threadRenewalDelay
After 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.
-
-
Method Detail
-
startInternal
protected void startInternal() throws LifecycleExceptionStart 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
protected void stopInternal() throws LifecycleExceptionStop 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
public void execute(java.lang.Runnable command)
- Specified by:
executein interfacejava.util.concurrent.Executor
-
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
public java.lang.String getNamePrefix()
Return the name prefix for new threads.- Returns:
- the name prefix
-
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
public java.lang.String getName()
Description copied from interface:ExecutorReturns the name of this executor.
-
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
public void setNamePrefix(java.lang.String namePrefix)
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
public void setName(java.lang.String name)
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
protected java.lang.String 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
protected java.lang.String 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 interfacejava.util.concurrent.ExecutorService
-
shutdownNow
public java.util.List<java.lang.Runnable> shutdownNow()
- Specified by:
shutdownNowin interfacejava.util.concurrent.ExecutorService
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdownin interfacejava.util.concurrent.ExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminatedin interfacejava.util.concurrent.ExecutorService
-
awaitTermination
public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException- Specified by:
awaitTerminationin interfacejava.util.concurrent.ExecutorService- Throws:
java.lang.InterruptedException
-
submit
public <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
- Specified by:
submitin interfacejava.util.concurrent.ExecutorService
-
submit
public <T> java.util.concurrent.Future<T> submit(java.lang.Runnable task, T result)- Specified by:
submitin interfacejava.util.concurrent.ExecutorService
-
submit
public java.util.concurrent.Future<?> submit(java.lang.Runnable task)
- Specified by:
submitin interfacejava.util.concurrent.ExecutorService
-
invokeAll
public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks) throws java.lang.InterruptedException- Specified by:
invokeAllin interfacejava.util.concurrent.ExecutorService- Throws:
java.lang.InterruptedException
-
invokeAll
public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException- Specified by:
invokeAllin interfacejava.util.concurrent.ExecutorService- Throws:
java.lang.InterruptedException
-
invokeAny
public <T> T invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException- Specified by:
invokeAnyin interfacejava.util.concurrent.ExecutorService- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionException
-
invokeAny
public <T> T invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException- Specified by:
invokeAnyin interfacejava.util.concurrent.ExecutorService- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.util.concurrent.TimeoutException
-
-