Package org.jboss.threads
Class EnhancedQueueExecutor.Builder
- java.lang.Object
-
- org.jboss.threads.EnhancedQueueExecutor.Builder
-
- Enclosing class:
- EnhancedQueueExecutor
public static final class EnhancedQueueExecutor.Builder extends Object
The builder class for anEnhancedQueueExecutor. All the fields are initialized to sensible defaults for a small thread pool.
-
-
Constructor Summary
Constructors Constructor Description Builder()Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description EnhancedQueueExecutor.BuilderallowCoreThreadTimeOut(boolean allowCoreTimeOut)Establish whether core threads are allowed to time out.booleanallowsCoreThreadTimeOut()Determine whether core threads are allowed to time out.EnhancedQueueExecutorbuild()Construct the executor from the configured parameters.intgetCorePoolSize()Get the core pool size.Thread.UncaughtExceptionHandlergetExceptionHandler()Get the uncaught exception handler.floatgetGrowthResistance()Get the thread pool growth resistance.ExecutorgetHandoffExecutor()Get the handoff executor.DurationgetKeepAliveTime()Get the thread keep-alive time.longgetKeepAliveTime(TimeUnit keepAliveUnits)Deprecated.UsegetKeepAliveTime()instead.intgetMaximumPoolSize()Get the maximum pool size.intgetMaximumQueueSize()Get the maximum queue size.StringgetMBeanName()Get the overridden MBean name.RunnablegetTerminationTask()Get the termination task.ThreadFactorygetThreadFactory()Get the configured thread factory.booleanisRegisterMBean()Determine whether an MBean should automatically be registered for this pool.EnhancedQueueExecutor.BuildersetCorePoolSize(int coreSize)Set the core pool size.EnhancedQueueExecutor.BuildersetExceptionHandler(Thread.UncaughtExceptionHandler exceptionHandler)Set the uncaught exception handler.EnhancedQueueExecutor.BuildersetGrowthResistance(float growthResistance)Set the thread pool growth resistance.EnhancedQueueExecutor.BuildersetHandoffExecutor(Executor handoffExecutor)Set the handoff executor.EnhancedQueueExecutor.BuildersetKeepAliveTime(long keepAliveTime, TimeUnit keepAliveUnits)Deprecated.UsesetKeepAliveTime(Duration)instead.EnhancedQueueExecutor.BuildersetKeepAliveTime(Duration keepAliveTime)Set the thread keep-alive time.EnhancedQueueExecutor.BuildersetMaximumPoolSize(int maxSize)Set the maximum pool size.EnhancedQueueExecutor.BuildersetMaximumQueueSize(int maxQueueSize)Set the maximum queue size.EnhancedQueueExecutor.BuildersetMBeanName(String mBeanName)Set the overridden MBean name.EnhancedQueueExecutor.BuildersetRegisterMBean(boolean registerMBean)Establish whether an MBean should automatically be registered for this pool.EnhancedQueueExecutor.BuildersetTerminationTask(Runnable terminationTask)Set the termination task.EnhancedQueueExecutor.BuildersetThreadFactory(ThreadFactory threadFactory)Set the configured thread factory.
-
-
-
Method Detail
-
getThreadFactory
public ThreadFactory getThreadFactory()
Get the configured thread factory.- Returns:
- the configured thread factory (not
null)
-
setThreadFactory
public EnhancedQueueExecutor.Builder setThreadFactory(ThreadFactory threadFactory)
Set the configured thread factory.- Parameters:
threadFactory- the configured thread factory (must not benull)- Returns:
- this builder
-
getTerminationTask
public Runnable getTerminationTask()
Get the termination task. By default, an emptyRunnableis used.- Returns:
- the termination task (not
null)
-
setTerminationTask
public EnhancedQueueExecutor.Builder setTerminationTask(Runnable terminationTask)
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:
EnhancedQueueExecutor.getCorePoolSize()
-
setCorePoolSize
public EnhancedQueueExecutor.Builder setCorePoolSize(int coreSize)
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:
EnhancedQueueExecutor.setCorePoolSize(int)
-
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:
EnhancedQueueExecutor.getMaximumPoolSize()
-
setMaximumPoolSize
public EnhancedQueueExecutor.Builder setMaximumPoolSize(int maxSize)
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:
EnhancedQueueExecutor.setMaximumPoolSize(int)
-
getKeepAliveTime
public Duration 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 public long getKeepAliveTime(TimeUnit keepAliveUnits)
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:
EnhancedQueueExecutor.getKeepAliveTime(TimeUnit)
-
setKeepAliveTime
public EnhancedQueueExecutor.Builder setKeepAliveTime(Duration keepAliveTime)
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:
EnhancedQueueExecutor.setKeepAliveTime(long, TimeUnit)
-
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:
EnhancedQueueExecutor.getGrowthResistance()
-
setGrowthResistance
public EnhancedQueueExecutor.Builder setGrowthResistance(float growthResistance)
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:
getGrowthResistance(),EnhancedQueueExecutor.setGrowthResistance(float)
-
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:
EnhancedQueueExecutor.allowsCoreThreadTimeOut()
-
allowCoreThreadTimeOut
public EnhancedQueueExecutor.Builder allowCoreThreadTimeOut(boolean allowCoreTimeOut)
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:
EnhancedQueueExecutor.allowCoreThreadTimeOut(boolean)
-
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:
EnhancedQueueExecutor.getMaximumQueueSize()
-
setMaximumQueueSize
public EnhancedQueueExecutor.Builder setMaximumQueueSize(int maxQueueSize)
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:
EnhancedQueueExecutor.setMaximumQueueSize(int)
-
getHandoffExecutor
public Executor getHandoffExecutor()
Get the handoff executor.- Returns:
- the handoff executor (not
null)
-
setHandoffExecutor
public EnhancedQueueExecutor.Builder setHandoffExecutor(Executor handoffExecutor)
Set the handoff executor.- Parameters:
handoffExecutor- the handoff executor (must not benull)- Returns:
- this builder
-
getExceptionHandler
public Thread.UncaughtExceptionHandler 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
public EnhancedQueueExecutor 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
public EnhancedQueueExecutor.Builder setRegisterMBean(boolean registerMBean)
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
public String getMBeanName()
Get the overridden MBean name.- Returns:
- the overridden MBean name, or
nullif a default name should be generated
-
setMBeanName
public EnhancedQueueExecutor.Builder setMBeanName(String mBeanName)
Set the overridden MBean name.- Parameters:
mBeanName- the overridden MBean name, ornullif a default name should be generated- Returns:
- this builder
-
-