Interface StandardThreadPoolMXBean
public interface StandardThreadPoolMXBean
An MXBean which contains the attributes and operations found on all standard thread pools.
-
Method Summary
Modifier and TypeMethodDescriptionintGet an estimate of the current number of active (busy) threads.longGet an estimate of the number of tasks completed by this thread pool.intGet the core pool size.floatGet the pool size growth resistance factor.longGet the thread keep-alive time, in seconds.intGet an estimate of the peak number of threads that the pool has ever held.intGet an estimate of the peak size of the queue, if any.intGet the maximum pool size.intGet the maximum queue size for this thread pool.intGet an estimate of the current number of active threads in the pool.intGet an estimate of the current queue size, if any.longGet an estimate of the total number of tasks ever rejected by this thread pool for any reason.default longGet the number of spin misses that have occurred.longGet an estimate of the total number of tasks ever submitted to this thread pool.booleanDetermine whether core threads are allowed to time out.booleanDetermine whether this implementation supports a separate core pool size.booleanDetermine whether this thread pool allows manual pre-start of core threads.booleanDetermine whether the thread pool supports a growth resistance factor.booleanDetermine whether there is a bounded queue backing this thread pool.booleanDetermine whether the maximum queue size is modifiable.booleanDetermine whether shutdown was requested.booleanDetermine whether shutdown is complete.booleanDetermine whether shutdown is in progress.intAttempt to start all core threads.booleanAttempt to start a core thread without submitting work to it.voidsetAllowCoreThreadTimeOut(boolean value) Establish whether core threads are allowed to time out.voidsetCorePoolSize(int corePoolSize) Set the core pool size.voidsetGrowthResistance(float value) Set the pool size growth resistance factor, if supported.voidsetKeepAliveTimeSeconds(long seconds) Set the thread keep-alive time, in seconds.voidsetMaximumPoolSize(int maxPoolSize) Set the maximum pool size.voidsetMaximumQueueSize(int size) Set the maximum queue size for this thread pool.
-
Method Details
-
getGrowthResistance
float getGrowthResistance()Get the pool size growth resistance factor. If the thread pool does not support growth resistance, then0.0(no resistance) is returned.- Returns:
- the growth resistance factor (
0.0 ≤ n ≤ 1.0)
-
setGrowthResistance
void setGrowthResistance(float value) Set the pool size growth resistance factor, if supported.- Parameters:
value- the growth resistance factor (0.0 ≤ n ≤ 1.0)
-
isGrowthResistanceSupported
boolean isGrowthResistanceSupported()Determine whether the thread pool supports a growth resistance factor.- Returns:
trueif the growth resistance factor is supported,falseotherwise
-
getCorePoolSize
int getCorePoolSize()Get the core pool size. This is the size below which new threads will always be created if no idle threads are available. If the thread pool does not support a separate core pool size, this size will match the maximum size.- Returns:
- the core pool size
-
setCorePoolSize
void setCorePoolSize(int corePoolSize) Set the core pool size. If the configured maximum pool size is less than the configured core size, the core size will be reduced to match the maximum size when the thread pool is constructed. If the thread pool does not support a separate core pool size, this setting will be ignored.- Parameters:
corePoolSize- the core pool size (must be greater than or equal to 0)
-
isCorePoolSizeSupported
boolean isCorePoolSizeSupported()Determine whether this implementation supports a separate core pool size.- Returns:
trueif a separate core size is supported;falseotherwise
-
prestartCoreThread
boolean prestartCoreThread()Attempt to start a core thread without submitting work to it.- Returns:
trueif the thread was started, orfalseif the pool is filled to the core size, the thread could not be created, or prestart of core threads is not supported.
-
prestartAllCoreThreads
int prestartAllCoreThreads()Attempt to start all core threads. This is usually equivalent to callingprestartCoreThread()in a loop until it returnsfalseand counting thetrueresults.- Returns:
- the number of started core threads (may be 0)
-
isCoreThreadPrestartSupported
boolean isCoreThreadPrestartSupported()Determine whether this thread pool allows manual pre-start of core threads.- Returns:
trueif pre-starting core threads is supported,falseotherwise
-
getMaximumPoolSize
int getMaximumPoolSize()Get the maximum pool size. This is the absolute upper limit to the size of the thread pool.- Returns:
- the maximum pool size
-
setMaximumPoolSize
void setMaximumPoolSize(int maxPoolSize) Set the maximum pool size. If the configured maximum pool size is less than the configured core size, the core size will be reduced to match the maximum size when the thread pool is constructed.- Parameters:
maxPoolSize- the maximum pool size (must be greater than or equal to 0)
-
getPoolSize
int getPoolSize()Get an estimate of the current number of active threads in the pool.- Returns:
- an estimate of the current number of active threads in the pool
-
getLargestPoolSize
int getLargestPoolSize()Get an estimate of the peak number of threads that the pool has ever held.- Returns:
- an estimate of the peak number of threads that the pool has ever held
-
getActiveCount
int getActiveCount()Get an estimate of the current number of active (busy) threads.- Returns:
- an estimate of the active count
-
isAllowCoreThreadTimeOut
boolean isAllowCoreThreadTimeOut()Determine whether core threads are allowed to time out. A "core thread" is defined as any thread in the pool when the pool size is below the pool's core pool size. If the thread pool does not support a separate core pool size, this method should returnfalse.This method is named differently from the typical
allowsCoreThreadTimeOut()in order to accommodate the requirements of MXBean attribute methods.- Returns:
trueif core threads are allowed to time out,falseotherwise
-
setAllowCoreThreadTimeOut
void setAllowCoreThreadTimeOut(boolean value) Establish whether core threads are allowed to time out. A "core thread" is defined as any thread in the pool when the pool size is below the pool's core pool size. If the thread pool does not support a separate core pool size, the value is ignored.This method is named differently from the typical
allowCoreThreadTimeOut(boolean)in order to accommodate the requirements of MXBean attribute methods.- Parameters:
value-trueif core threads are allowed to time out,falseotherwise
-
getKeepAliveTimeSeconds
long getKeepAliveTimeSeconds()Get the thread keep-alive time, in seconds.This method differs from the typical
getKeepAliveTime(TimeUnit)due to the inability to send in a time units parameter on an MXBean attribute. As such, the unit is hard-coded to seconds.- Returns:
- the thread keep-alive time, in seconds
-
setKeepAliveTimeSeconds
void setKeepAliveTimeSeconds(long seconds) Set the thread keep-alive time, in seconds.This method differs from the typical
getKeepAliveTime(TimeUnit)due to the inability to send in a time units parameter on an MXBean attribute. As such, the unit is hard-coded to seconds.- Parameters:
seconds- the thread keep-alive time, in seconds (must be greater than or equal to 0)
-
getMaximumQueueSize
int getMaximumQueueSize()Get the maximum queue size for this thread pool. If there is no queue or it is not bounded,Integer.MAX_VALUEis returned.- Returns:
- the maximum queue size
-
setMaximumQueueSize
void setMaximumQueueSize(int size) Set the maximum queue size for this thread pool. If the new maximum queue size is smaller than the current queue size, there is no effect other than preventing tasks from being enqueued until the size decreases below the maximum again. If changing the maximum queue size is not supported, or there is no bounded backing queue, then the value is ignored.- Parameters:
size- the maximum queue size for this thread pool
-
getQueueSize
int getQueueSize()Get an estimate of the current queue size, if any. If no backing queue exists, or its size cannot be determined, this method will return 0.- Returns:
- an estimate of the current queue size
-
getLargestQueueSize
int getLargestQueueSize()Get an estimate of the peak size of the queue, if any. If no backing queue exists, or its size cannot be determined, this method will return 0.- Returns:
- an estimate of the peak size of the queue
-
isQueueBounded
boolean isQueueBounded()Determine whether there is a bounded queue backing this thread pool.- Returns:
trueif there is a bounded backing queue,falseotherwise
-
isQueueSizeModifiable
boolean isQueueSizeModifiable()Determine whether the maximum queue size is modifiable.- Returns:
trueif the queue size is modifiable, false otherwise
-
isShutdown
boolean isShutdown()Determine whether shutdown was requested.- Returns:
trueif shutdown was requested,falseotherwise
-
isTerminating
boolean isTerminating()Determine whether shutdown is in progress.- Returns:
trueif shutdown is in progress,falseotherwise
-
isTerminated
boolean isTerminated()Determine whether shutdown is complete.- Returns:
trueif shutdown is complete,falseotherwise
-
getSubmittedTaskCount
long getSubmittedTaskCount()Get an estimate of the total number of tasks ever submitted to this thread pool. This number may be zero if the underlying thread pool does not support this metric.- Returns:
- an estimate of the total number of tasks ever submitted to this thread pool
-
getRejectedTaskCount
long getRejectedTaskCount()Get an estimate of the total number of tasks ever rejected by this thread pool for any reason. This number may be zero if the underlying thread pool does not support this metric.- Returns:
- an estimate of the total number of tasks ever rejected by this thread pool
-
getCompletedTaskCount
long getCompletedTaskCount()Get an estimate of the number of tasks completed by this thread pool. This number may be zero if the underlying thread pool does not support this metric.- Returns:
- an estimate of the number of tasks completed by this thread pool
-
getSpinMissCount
default long getSpinMissCount()Get the number of spin misses that have occurred. Spin misses indicate that contention is not being properly handled by the thread pool.- Returns:
- an estimate of the number of spin misses
-