A TryExecutor using pre-allocated/reserved threads from an external Executor.
Calls to tryExecute(Runnable) on ReservedThreadExecutor will either
succeed with a reserved thread immediately being assigned the task, or fail if
no reserved thread is available.
Threads are reserved lazily, with new reserved threads being allocated from the external
Executor passed to the constructor. Whenever 1 or more reserved threads have been
idle for more than getIdleTimeoutMs() then one reserved thread will return to
the external Executor.
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| private static enum |
| Modifier and Type | Field and Description |
|---|---|
| private final int | |
| private final AtomicBiInteger | |
| private final Executor | |
| private long | |
| private final AtomicLong | |
| private ThreadPoolBudget. | |
| private final SynchronousQueue | |
| private final Set | |
| private static final long | |
| private static final Logger | |
| private static final Runnable |
| Access | Constructor and Description |
|---|---|
| public | ReservedThreadExecutor(Executor
The executor to use to obtain threads executor, int The number of threads to preallocate. If less than 0 then capacity
is calculated based on a heuristic from the number of available processors and
thread pool size. capacity)
|
| Modifier and Type | Method and Description |
|---|---|
| public void | doStart()
Overrides org. |
| public void | doStop()
Overrides org. |
| public void | dump(Appendable
The appendable to dump to out, String The indent to apply after any new lines. indent)Implements org. |
| public void | execute(Runnable
the runnable task task)Overrides default org. |
| public int | |
| public int | |
| public Executor | |
| public long | |
| public int | |
| private static int | Returns: the number of reserved threads that would be used by a ReservedThreadExecutor constructed with these arguments.The executor to use to obtain threads executor, int The number of threads to preallocate, If less than 0 then capacity
is calculated based on a heuristic from the number of available processors and
thread pool size. capacity)
|
| public void | setIdleTimeout(long
Time to wait before shrinking, or 0 for default timeout. idleTime, TimeUnit Time units for idle timeout idleTimeUnit)Set the idle timeout for shrinking the reserved thread pool |
| private void | |
| public String | toString()
Overrides org. |
| public boolean | Returns: true if and only if a reserved thread was available and has been assigned the task to run.the task to run task)Implements org. Executes the given task if and only if a reserved thread is available. |
| _capacity | back to summary |
|---|---|
| private final int _capacity | |
| _count | back to summary |
|---|---|
| private final AtomicBiInteger _count | |
| _executor | back to summary |
|---|---|
| private final Executor _executor | |
| _idleTimeNanos | back to summary |
|---|---|
| private long _idleTimeNanos | |
| _lastEmptyNanoTime | back to summary |
|---|---|
| private final AtomicLong _lastEmptyNanoTime | |
| _lease | back to summary |
|---|---|
| private ThreadPoolBudget. | |
| _queue | back to summary |
|---|---|
| private final SynchronousQueue<Runnable> _queue | |
| _threads | back to summary |
|---|---|
| private final Set<ReservedThreadExecutor. | |
| DEFAULT_IDLE_TIMEOUT | back to summary |
|---|---|
| private static final long DEFAULT_IDLE_TIMEOUT | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG Hides org. | |
| STOP | back to summary |
|---|---|
| private static final Runnable STOP | |
| ReservedThreadExecutor | back to summary |
|---|---|
public ReservedThreadExecutor(Executor executor, int capacity)
| |
| doStart | back to summary |
|---|---|
| public void doStart() throws Exception Overrides org. Doc from org. Method to override to start the lifecycle | |
| doStop | back to summary |
|---|---|
| public void doStop() throws Exception Overrides org. Doc from org. Method to override to stop the lifecycle | |
| dump | back to summary |
|---|---|
| public void dump(Appendable out, String indent) throws IOException Implements org. Doc from org. Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
| |
| execute | back to summary |
|---|---|
| public void execute(Runnable task) throws RejectedExecutionException Overrides default org. Doc from java. Executes the given command at some time in the future. The command
may execute in a new thread, in a pooled thread, or in the calling
thread, at the discretion of the
| |
| getAvailable | back to summary |
|---|---|
public int getAvailable()
| |
| getCapacity | back to summary |
|---|---|
public int getCapacity()
| |
| getExecutor | back to summary |
|---|---|
| public Executor getExecutor() | |
| getIdleTimeoutMs | back to summary |
|---|---|
public long getIdleTimeoutMs()
| |
| getPending | back to summary |
|---|---|
public int getPending()
| |
| reservedThreads | back to summary |
|---|---|
private static int reservedThreads(Executor executor, int capacity)
| |
| setIdleTimeout | back to summary |
|---|---|
| public void setIdleTimeout(long idleTime, TimeUnit idleTimeUnit) Set the idle timeout for shrinking the reserved thread pool
| |
| startReservedThread | back to summary |
|---|---|
| private void startReservedThread() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides org. Doc from java. Returns a string representation of the object. | |
| tryExecute | back to summary |
|---|---|
| public boolean tryExecute(Runnable task) Implements org. Executes the given task if and only if a reserved thread is available. | |
| Modifier and Type | Field and Description |
|---|---|
| private volatile ReservedThreadExecutor. | |
| private volatile Thread |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private boolean | |
| private Runnable | |
| public void | |
| public String |
| _state | back to summary |
|---|---|
| private volatile ReservedThreadExecutor. | |
| _thread | back to summary |
|---|---|
| private volatile Thread _thread | |
| ReservedThread | back to summary |
|---|---|
| private ReservedThread() | |
| isReserved | back to summary |
|---|---|
| private boolean isReserved() | |
| reservedWait | back to summary |
|---|---|
| private Runnable reservedWait() | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Modifier and Type | Field and Description |
|---|---|
| public static final ReservedThreadExecutor. | |
| public static final ReservedThreadExecutor. | |
| public static final ReservedThreadExecutor. | |
| public static final ReservedThreadExecutor. | |
| public static final ReservedThreadExecutor. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static ReservedThreadExecutor. | |
| public static ReservedThreadExecutor. |
| IDLE | back to summary |
|---|---|
| public static final ReservedThreadExecutor. | |
| PENDING | back to summary |
|---|---|
| public static final ReservedThreadExecutor. | |
| RESERVED | back to summary |
|---|---|
| public static final ReservedThreadExecutor. | |
| RUNNING | back to summary |
|---|---|
| public static final ReservedThreadExecutor. | |
| STOPPED | back to summary |
|---|---|
| public static final ReservedThreadExecutor. | |
| State | back to summary |
|---|---|
| private State() | |
| valueOf | back to summary |
|---|---|
| public static ReservedThreadExecutor. | |
| values | back to summary |
|---|---|
| public static ReservedThreadExecutor. | |