Top Description Inners Fields Constructors Methods
org.jboss.threads

public final Class EnhancedQueueExecutor

extends EnhancedQueueExecutorBase6
implements ManageableThreadPoolExecutorService, ScheduledExecutorService
Class Inheritance
All Implemented Interfaces
java.util.concurrent.ScheduledExecutorService, java.util.concurrent.ExecutorService, java.lang.AutoCloseable, java.util.concurrent.Executor, org.jboss.threads.management.ManageableThreadPoolExecutorService
Static Imports
java.lang.Math.max, .Math.min, .Thread.currentThread, java.security.AccessController.doPrivileged, .AccessController.getContext, java.util.concurrent.locks.LockSupport.parkNanos, .LockSupport.unpark, org.jboss.threads.JBossExecutors.unsafe

A task-or-thread queue backed thread pool executor service. Tasks are added in a FIFO manner, and consumers in a LIFO manner. Threads are only ever created in the event that there are no idle threads available to service a task, which, when combined with the LIFO-based consumer behavior, means that the thread pool will generally trend towards the minimum necessary size. In addition, the optional growth resistance feature can be used to further govern the thread pool size.

Additionally, this thread pool implementation supports scheduling of tasks. The scheduled tasks will execute on the main pool.

New instances of this thread pool are created by constructing and configuring a Builder instance, and calling its build() method.

Author
David M. Lloyd

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract class
EnhancedQueueExecutor.AbstractScheduledFuture<
the result type
V
>

An implementation of ScheduledFuture which is wrapped by Task.

pack-priv static class
public static class
EnhancedQueueExecutor.Builder

The builder class for an EnhancedQueueExecutor.

pack-priv class
pack-priv class
pack-priv class
pack-priv static class
pack-priv static class
pack-priv class
pack-priv static class
pack-priv abstract static class
EnhancedQueueExecutor.PoolThreadNodeBase

Padding between PoolThreadNode task and parked fields and QNode.next

pack-priv abstract static class
pack-priv static class
pack-priv abstract class
pack-priv class
pack-priv static interface
pack-priv class
pack-priv class
pack-priv static class
pack-priv static class
pack-priv class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private volatile AccessControlContext
acc

The access control context of the creating thread.

pack-priv static final Runnable
pack-priv volatile int
activeCount

The current active number of threads.

private static final long
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
private static final int
private static final int
private static final int
private final LongAdder
private final ContextHandler<?>
contextHandler

The context handler for the user-defined context.

pack-priv static final Executor
public static final boolean
DISABLE_HINT

A global hint which establishes whether it is recommended to disable uses of EnhancedQueueExecutor.

pack-priv static final boolean
DISABLE_MBEAN

Set to enable or disable MBean registration.

pack-priv volatile Thread.UncaughtExceptionHandler
exceptionHandler

The handler for uncaught exceptions which occur during user tasks.

private static final int
private static final int
private static final int
private static final int
pack-priv static final Runnable
pack-priv static final Runnable
pack-priv volatile float
growthResistance

A resistance factor applied after the core pool is full; values applied here will cause that fraction of submissions to create new threads when no idle thread is available.

private final Object
handle

The MBean registration handle (if any).

pack-priv volatile Executor
handoffExecutor

The handler for tasks which cannot be accepted by the executor.

private final EnhancedQueueExecutor.MXBeanImpl
mxBean

The management bean instance.

pack-priv static final EnhancedQueueExecutor.AbstractScheduledFuture<?>[]
pack-priv static final boolean
NO_QUEUE_LIMIT

Suppress queue limit and size tracking for performance.

private static final Thread[]
pack-priv static final int
PARK_SPINS

The number of times a thread should spin/yield before actually parking.

pack-priv volatile int
peakQueueSize

The approximate peak queue size.

private static final long
pack-priv volatile int
peakThreadCount

The peak number of threads ever created by this pool.

private static final long
pack-priv volatile long
queueSize

Queue size:

  • Bit 00..1F: current queue length
  • Bit 20..3F: queue limit
private static final long
pack-priv static final boolean
REGISTER_MBEAN

Set the default value for whether an mbean is to be auto-registered for the thread pool.

private final LongAdder
private final Set<Thread>
runningThreads

The approximate set of pooled threads.

pack-priv static final AtomicLong
private final EnhancedQueueExecutor.SchedulerTask
schedulerTask

The task for scheduled execution.

private final Thread
schedulerThread

The scheduler thread.

pack-priv static final AtomicInteger
private final LongAdder
private final LongAdder
pack-priv static final EnhancedQueueExecutor.QNode
pack-priv static final Waiter
pack-priv static final EnhancedQueueExecutor.QNode
pack-priv volatile Runnable
terminationTask

The termination task to execute when the thread pool exits.

pack-priv volatile Waiter
terminationWaiters

The linked list of threads waiting for termination of this thread pool.

private static final long
private final ThreadFactory
threadFactory

The thread factory.

pack-priv volatile long
timeoutNanos

The thread keep-alive timeout value.

private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
pack-priv static final boolean
UPDATE_ACTIVE_COUNT

Maintain an estimate of the number of threads which are currently doing work on behalf of the thread pool.

pack-priv static final boolean
UPDATE_STATISTICS

Update the summary statistics.

pack-priv static final Runnable
pack-priv static final int
YIELD_FACTOR

The yield ratio expressed as the number of spins that should yield.

Inherited from org.jboss.threads.EnhancedQueueExecutorBase6:
p00p01p02p03p04p05p06p07p08p09p0Ap0Bp0Cp0Dp0Ep0F

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
allowCoreThreadTimeOut(boolean
true if core threads are allowed to time out, false otherwise
value
)

Establish whether core threads are allowed to time out.

public boolean

Returns:

true if core threads are allowed to time out, false otherwise
allowsCoreThreadTimeOut
()

Determine whether core threads are allowed to time out.

public boolean

Returns:

true if the thread pool terminated within the given timeout, false otherwise
awaitTermination
(final long
the amount of time to wait (must be ≥ 0)
timeout
,
final TimeUnit
the unit of time to use for waiting (must not be null)
unit
)

Implements java.util.concurrent.ExecutorService.awaitTermination.

Wait for the thread pool to complete termination.
pack-priv boolean
compareAndSetPeakQueueSize(final int expect, final int update)

pack-priv boolean
compareAndSetPeakThreadCount(final int expect, final int update)

pack-priv boolean
compareAndSetQueueSize(final long expect, final long update)

pack-priv boolean
compareAndSetTerminationWaiters(final Waiter expect, final Waiter update)

pack-priv void
pack-priv static int
coreSizeOf(long status)

pack-priv static int
currentQueueSizeOf(long queueSize)

pack-priv static int
currentSizeOf(long status)

pack-priv void
deallocateThread()

Roll back a thread allocation, possibly terminating the pool.

pack-priv void
pack-priv void
pack-priv boolean

Returns:

true if the thread was started, false otherwise
doStartThread
(EnhancedQueueExecutor.Task
the task or null
runnable
)

Start an allocated thread.

public void
execute(Runnable
the task to execute (must not be null)
runnable
)

Implements java.util.concurrent.Executor.execute.

Execute a task.
public int

Returns:

the active count estimate or -1 when jboss.threads.eqe.statistics.active-count is disabled
getActiveCount
()

Get an estimate of the number of threads which are currently doing work on behalf of the thread pool.

pack-priv Waiter
public long

Returns:

an estimate of the number of tasks completed by this thread pool or -1 when jboss.threads.eqe.statistics is disabled
getCompletedTaskCount
()

Get an estimate of the number of tasks completed by this thread pool.

public int

Returns:

the core pool size
getCorePoolSize
()

Get the core pool size.

public Thread.UncaughtExceptionHandler

Returns:

the exception handler to use for uncaught exceptions (not null)
getExceptionHandler
()

Get the exception handler to use for uncaught exceptions.

public float

Returns:

the configured growth resistance factor
getGrowthResistance
()

Get the thread pool growth resistance.

public Executor

Returns:

the executor to delegate to in the event of task rejection (not null)
getHandoffExecutor
()

Get the executor to delegate to in the event of task rejection.

public long

Returns:

the amount of time (will be greater than zero)
getKeepAliveTime
(TimeUnit
the unit in which the result should be expressed (must not be null)
keepAliveUnits
)

Deprecated Use getKeepAliveTime() instead.
Get the thread keep-alive time.
public Duration

Returns:

the amount of time (will be greater than zero)
getKeepAliveTime
()

Get the thread keep-alive time.

public int

Returns:

an estimate of the peak number of threads that the pool has ever held
getLargestPoolSize
()

Get an estimate of the peak number of threads that the pool has ever held.

public int
getLargestQueueSize()

Get an estimate of the peak size of the queue.

public int

Returns:

the maximum pool size
getMaximumPoolSize
()

Get the maximum pool size.

public int

Returns:

the maximum queue size
getMaximumQueueSize
()

Get the maximum queue size.

public int

Returns:

an estimate of the current number of active threads in the pool
getPoolSize
()

Get an estimate of the current number of active threads in the pool.

public int

Returns:

an estimate of the current queue size or -1 when jboss.threads.eqe.unlimited-queue is enabled
getQueueSize
()

Get an estimate of the current queue size.

public long

Returns:

an estimate of the total number of tasks ever rejected by this thread pool or -1 when jboss.threads.eqe.statistics is disabled
getRejectedTaskCount
()

Get an estimate of the total number of tasks ever rejected by this thread pool for any reason.

public Thread[]

Returns:

an array of running (unterminated) threads (not null)
getRunningThreads
()

Get an array containing an approximate snapshot of the currently running threads in this executor.

public long

Returns:

an estimate of the total number of tasks ever submitted to this thread pool or -1 when jboss.threads.eqe.statistics is disabled
getSubmittedTaskCount
()

Get an estimate of the total number of tasks ever submitted to this thread pool.

public StandardThreadPoolMXBean
getThreadPoolMXBean()

Implements org.jboss.threads.management.ManageableThreadPoolExecutorService.getThreadPoolMXBean.

Create or acquire an MXBean instance for this thread pool.
pack-priv boolean
pack-priv void
pack-priv static boolean
isAllowCoreTimeout(final long oldVal)

public boolean

Returns:

true if shutdown was requested, false otherwise
isShutdown
()

Implements java.util.concurrent.ExecutorService.isShutdown.

Determine whether shutdown was requested on this thread pool.
pack-priv static boolean
isShutdownComplete(final long status)

pack-priv static boolean
isShutdownInterrupt(final long threadStatus)

pack-priv static boolean
isShutdownRequested(final long status)

public boolean

Returns:

true if shutdown has completed, false otherwise
isTerminated
()

Implements java.util.concurrent.ExecutorService.isTerminated.

Determine whether shutdown has completed on this thread pool.
public boolean

Returns:

true if the thread pool is terminating, or false if the thread pool is not terminating or has completed termination
isTerminating
()

Determine if this thread pool is in the process of terminating but has not yet completed.

pack-priv static int
maxQueueSizeOf(long queueSize)

pack-priv static int
maxSizeOf(long status)

pack-priv static Runnable
nullToNop(final Runnable task)

public int

Returns:

the number of core threads created
prestartAllCoreThreads
()

Start all core threads.

public boolean

Returns:

true if a core thread was started, or false if all core threads were already running or if the thread failed to be created for some other reason
prestartCoreThread
()

Start an idle core thread.

pack-priv void
pack-priv void
pack-priv void
pack-priv void
public ScheduledFuture<?>
schedule(final Runnable
the task to execute
command
,
final long
the time from now to delay execution
delay
,
final TimeUnit
the time unit of the delay parameter
unit
)

Implements java.util.concurrent.ScheduledExecutorService.schedule.

Submits a one-shot task that becomes enabled after the given delay.
public <V> ScheduledFuture<V>
schedule(final Callable<V>
the function to execute
callable
,
final long
the time from now to delay execution
delay
,
final TimeUnit
the time unit of the delay parameter
unit
)

Implements java.util.concurrent.ScheduledExecutorService.schedule.

Submits a value-returning one-shot task that becomes enabled after the given delay.
public ScheduledFuture<?>
scheduleAtFixedRate(final Runnable
the task to execute
command
,
final long
the time to delay first execution
initialDelay
,
final long
the period between successive executions
period
,
final TimeUnit
the time unit of the initialDelay and period parameters
unit
)

Implements java.util.concurrent.ScheduledExecutorService.scheduleAtFixedRate.

Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is, executions will commence after initialDelay, then initialDelay + period, then initialDelay + 2 * period, and so on.
public ScheduledFuture<?>
scheduleWithFixedDelay(final Runnable
the task to execute
command
,
final long
the time to delay first execution
initialDelay
,
final long
the delay between the termination of one execution and the commencement of the next
delay
,
final TimeUnit
the time unit of the initialDelay and delay parameters
unit
)

Implements java.util.concurrent.ScheduledExecutorService.scheduleWithFixedDelay.

Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.
public void
setCorePoolSize(final int
the core pool size (must be greater than or equal to 0, and less than 2^20)
corePoolSize
)

Set the core pool size.

public void
setExceptionHandler(final Thread.UncaughtExceptionHandler
the exception handler to use for uncaught exceptions (must not be null)
exceptionHandler
)

Set the exception handler to use for uncaught exceptions.

public void
setGrowthResistance(final float
the thread pool growth resistance (must be in the range 0.0f ≤ n ≤ 1.0f)
growthResistance
)

Set the growth resistance factor.

public void
setHandoffExecutor(final Executor
the executor to delegate to in the event of task rejection (must not be null)
handoffExecutor
)

Set the executor to delegate to in the event of task rejection.

public void
setKeepAliveTime(final long
the thread keep-alive time (must be > 0)
keepAliveTime
,
final TimeUnit
the unit in which the value is expressed (must not be null)
keepAliveUnits
)

Deprecated Use setKeepAliveTime(Duration) instead.
Set the thread keep-alive time.
public void
setKeepAliveTime(final Duration
the thread keep-alive time (must not be null)
keepAliveTime
)

Set the thread keep-alive time.

public void
setMaximumPoolSize(final int
the maximum pool size (must be greater than or equal to 0, and less than 2^20)
maxPoolSize
)

Set the maximum pool size.

public void
setMaximumQueueSize(final int
the maximum queue size (must be ≥ 0)
maxQueueSize
)

Set the maximum queue size.

public void
setTerminationTask(final Runnable
the termination task, or null to perform no termination task
terminationTask
)

Set the termination task, overwriting any previous setting.

public void
shutdown()

Implements java.util.concurrent.ExecutorService.shutdown.

Request that shutdown be initiated for this thread pool.
public void
shutdown(boolean
true to request that currently-running tasks be interrupted; false otherwise
interrupt
)

Initiate shutdown of this thread pool.

public List<Runnable>

Returns:

a list of pending tasks (not null)
shutdownNow
()

Implements java.util.concurrent.ExecutorService.shutdownNow.

Attempt to stop the thread pool immediately by interrupting all running threads and de-queueing all pending tasks.
private void
pack-priv int

Returns:

AT_YES if a thread is allocated; AT_NO if a thread was not allocated; AT_SHUTDOWN if the pool is being shut down
tryAllocateThread
(final float
the growth resistance to apply
growthResistance
)

Allocate a new thread.

pack-priv boolean

Returns:

true if the thread was deallocated, or false to retry with a new oldStat
tryDeallocateThread
(long
the threadStatus to CAS
oldStat
)

Try to roll back a thread allocation, possibly running the termination task if the pool would be terminated by last thread exit.

private int
pack-priv static long
withAllowCoreTimeout(final long status, final boolean allowed)

pack-priv static long
withCoreSize(long status, int newCoreSize)

pack-priv static long
withCurrentQueueSize(long queueSize, int current)

pack-priv static long
withCurrentSize(long status, int newCurrentSize)

pack-priv static long
withMaxQueueSize(long queueSize, int max)

pack-priv static long
withMaxSize(long status, int newMaxSize)

pack-priv static long
withShutdownComplete(final long status)

pack-priv static long
withShutdownInterrupt(final long status)

pack-priv static long
withShutdownRequested(final long status)

pack-priv static int