Package org.jboss.threads
Class EnhancedQueueExecutor.Builder
java.lang.Object
org.jboss.threads.EnhancedQueueExecutor.Builder
- Enclosing class:
- EnhancedQueueExecutor
The builder class for an
EnhancedQueueExecutor. All the fields are initialized to sensible defaults for
a small thread pool.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionallowCoreThreadTimeOut(boolean allowCoreTimeOut) Establish whether core threads are allowed to time out.booleanDetermine whether core threads are allowed to time out.build()Construct the executor from the configured parameters.Get the context handler for the user-defined context.intGet the core pool size.Get the uncaught exception handler.floatGet the thread pool growth resistance.Get the handoff executor.Get the thread keep-alive time.longgetKeepAliveTime(TimeUnit keepAliveUnits) Deprecated.intGet the maximum pool size.intGet the maximum queue size.Get the overridden MBean name.Get the termination task.Get the configured thread factory.booleanDetermine whether an MBean should automatically be registered for this pool.setContextHandler(ContextHandler<?> contextHandler) Set the context handler for the user-defined context.setCorePoolSize(int coreSize) Set the core pool size.setExceptionHandler(Thread.UncaughtExceptionHandler exceptionHandler) Set the uncaught exception handler.setGrowthResistance(float growthResistance) Set the thread pool growth resistance.setHandoffExecutor(Executor handoffExecutor) Set the handoff executor.setKeepAliveTime(long keepAliveTime, TimeUnit keepAliveUnits) Deprecated.UsesetKeepAliveTime(Duration)instead.setKeepAliveTime(Duration keepAliveTime) Set the thread keep-alive time.setMaximumPoolSize(int maxSize) Set the maximum pool size.setMaximumQueueSize(int maxQueueSize) Set the maximum queue size.setMBeanName(String mBeanName) Set the overridden MBean name.setRegisterMBean(boolean registerMBean) Establish whether an MBean should automatically be registered for this pool.setTerminationTask(Runnable terminationTask) Set the termination task.setThreadFactory(ThreadFactory threadFactory) Set the configured thread factory.
-
Constructor Details
-
Builder
public Builder()Construct a new instance.
-
-
Method Details
-
getThreadFactory
Get the configured thread factory.- Returns:
- the configured thread factory (not
null)
-
setThreadFactory
Set the configured thread factory.- Parameters:
threadFactory- the configured thread factory (must not benull)- Returns:
- this builder
-
getTerminationTask
Get the termination task. By default, an emptyRunnableis used.- Returns:
- the termination task (not
null)
-
setTerminationTask
Set the termination task.- Parameters:
terminationTask- the termination task (must not benull)- Returns:
- this builder
-
getCorePoolSize
public 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 pool size reaches the core size but has not yet reached the maximum size, a resistance factor will be applied to each task submission which determines whether the task should be queued or a new thread started.- Returns:
- the core pool size
- See Also:
-
setCorePoolSize
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.- Parameters:
coreSize- the core pool size (must be greater than or equal to 0, and less than 2^20)- Returns:
- this builder
- See Also:
-
getMaximumPoolSize
public 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
- See Also:
-
setMaximumPoolSize
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:
maxSize- the maximum pool size (must be greater than or equal to 0, and less than 2^20)- Returns:
- this builder
- See Also:
-
getKeepAliveTime
Get the thread keep-alive time. This is the amount of time (in the configured time unit) that idle threads will wait for a task before exiting.- Returns:
- the thread keep-alive time duration
-
getKeepAliveTime
Deprecated.UsegetKeepAliveTime()instead.Get the thread keep-alive time. This is the amount of time (in the configured time unit) that idle threads will wait for a task before exiting.- Parameters:
keepAliveUnits- the time keepAliveUnits of the keep-alive time (must not benull)- Returns:
- the thread keep-alive time
- See Also:
-
setKeepAliveTime
Set the thread keep-alive time.- Parameters:
keepAliveTime- the thread keep-alive time (must not benull)
-
setKeepAliveTime
@Deprecated public EnhancedQueueExecutor.Builder setKeepAliveTime(long keepAliveTime, TimeUnit keepAliveUnits) Deprecated.UsesetKeepAliveTime(Duration)instead.Set the thread keep-alive time.- Parameters:
keepAliveTime- the thread keep-alive time (must be greater than 0)keepAliveUnits- the time keepAliveUnits of the keep-alive time (must not benull)- Returns:
- this builder
- See Also:
-
getGrowthResistance
public float getGrowthResistance()Get the thread pool growth resistance. This is the average fraction of submitted tasks that will be enqueued (instead of causing a new thread to start) when there are no idle threads and the pool size is equal to or greater than the core size (but still less than the maximum size). A value of0.0indicates that tasks should not be enqueued until the pool is completely full; a value of1.0indicates that tasks should always be enqueued until the queue is completely full.- Returns:
- the thread pool growth resistance
- See Also:
-
setGrowthResistance
Set the thread pool growth resistance.- Parameters:
growthResistance- the thread pool growth resistance (must be in the range0.0f ≤ n ≤ 1.0f)- Returns:
- this builder
- See Also:
-
allowsCoreThreadTimeOut
public boolean allowsCoreThreadTimeOut()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.- Returns:
trueif core threads are allowed to time out,falseotherwise- See Also:
-
allowCoreThreadTimeOut
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.- Parameters:
allowCoreTimeOut-trueif core threads are allowed to time out,falseotherwise- Returns:
- this builder
- See Also:
-
getMaximumQueueSize
public int getMaximumQueueSize()Get the maximum queue size. If the queue is full and a task cannot be immediately accepted, rejection will result.- Returns:
- the maximum queue size
- See Also:
-
setMaximumQueueSize
Set the maximum queue size. This has no impact whenjboss.threads.eqe.unlimited-queueis set.- Parameters:
maxQueueSize- the maximum queue size (must be ≥ 0)- Returns:
- this builder
- See Also:
-
getHandoffExecutor
Get the handoff executor.- Returns:
- the handoff executor (not
null)
-
setHandoffExecutor
Set the handoff executor.- Parameters:
handoffExecutor- the handoff executor (must not benull)- Returns:
- this builder
-
getExceptionHandler
Get the uncaught exception handler.- Returns:
- the uncaught exception handler (not
null)
-
setExceptionHandler
public EnhancedQueueExecutor.Builder setExceptionHandler(Thread.UncaughtExceptionHandler exceptionHandler) Set the uncaught exception handler.- Parameters:
exceptionHandler- the uncaught exception handler (must not benull)- Returns:
- this builder
-
build
Construct the executor from the configured parameters.- Returns:
- the executor, which will be active and ready to accept tasks (not
null)
-
isRegisterMBean
public boolean isRegisterMBean()Determine whether an MBean should automatically be registered for this pool.- Returns:
trueif an MBean is to be auto-registered;falseotherwise
-
setRegisterMBean
Establish whether an MBean should automatically be registered for this pool.- Parameters:
registerMBean-trueif an MBean is to be auto-registered;falseotherwise- Returns:
- this builder
-
getMBeanName
Get the overridden MBean name.- Returns:
- the overridden MBean name, or
nullif a default name should be generated
-
setMBeanName
Set the overridden MBean name.- Parameters:
mBeanName- the overridden MBean name, ornullif a default name should be generated- Returns:
- this builder
-
getContextHandler
Get the context handler for the user-defined context.- Returns:
- the context handler for the user-defined context (not
null)
-
setContextHandler
Set the context handler for the user-defined context.- Parameters:
contextHandler- the context handler for the user-defined context- Returns:
- this builder
-
getKeepAliveTime()instead.