java.util.concurrent.Executor, LifeCycle, TryExecutor@ManagedObject("A pool for reserved threads") public class ReservedThreadExecutor extends AbstractLifeCycle implements TryExecutor
Calls to execute(Runnable) on a ReservedThreadExecutor will either succeed
with a Thread immediately being assigned the Runnable task, or fail if no Thread is
available.
Threads are reserved lazily, with a new reserved thread being allocated from a
wrapped Executor when an execution fails. If the setIdleTimeout(long, TimeUnit)
is set to non zero (default 1 minute), then the reserved thread pool will shrink by 1 thread
whenever it has been idle for that period.
AbstractLifeCycle.AbstractLifeCycleListenerLifeCycle.ListenerTryExecutor.NoTryExecutorFAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPINGNO_TRY| Constructor | Description |
|---|---|
ReservedThreadExecutor(java.util.concurrent.Executor executor,
int capacity) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
doStart() |
|
void |
doStop() |
|
void |
execute(java.lang.Runnable task) |
|
int |
getAvailable() |
|
int |
getCapacity() |
|
java.util.concurrent.Executor |
getExecutor() |
|
long |
getIdleTimeoutMs() |
|
int |
getPending() |
|
void |
setIdleTimeout(long idleTime,
java.util.concurrent.TimeUnit idleTimeUnit) |
Set the idle timeout for shrinking the reserved thread pool
|
java.lang.String |
toString() |
|
boolean |
tryExecute(java.lang.Runnable task) |
Attempt to execute a task.
|
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stopclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitasTryExecutorpublic ReservedThreadExecutor(java.util.concurrent.Executor executor,
int capacity)
executor - The executor to use to obtain threadscapacity - 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.public java.util.concurrent.Executor getExecutor()
@ManagedAttribute(value="max number of reserved threads", readonly=true) public int getCapacity()
@ManagedAttribute(value="available reserved threads", readonly=true) public int getAvailable()
@ManagedAttribute(value="pending reserved threads", readonly=true) public int getPending()
@ManagedAttribute(value="idletimeout in MS", readonly=true) public long getIdleTimeoutMs()
public void setIdleTimeout(long idleTime,
java.util.concurrent.TimeUnit idleTimeUnit)
idleTime - Time to wait before shrinking, or 0 for no timeout.idleTimeUnit - Time units for idle timeoutpublic void doStart()
throws java.lang.Exception
doStart in class AbstractLifeCyclejava.lang.Exceptionpublic void doStop()
throws java.lang.Exception
doStop in class AbstractLifeCyclejava.lang.Exceptionpublic void execute(java.lang.Runnable task)
throws java.util.concurrent.RejectedExecutionException
execute in interface java.util.concurrent.Executorexecute in interface TryExecutorjava.util.concurrent.RejectedExecutionExceptionpublic boolean tryExecute(java.lang.Runnable task)
TryExecutortryExecute in interface TryExecutortask - The task to runpublic java.lang.String toString()
toString in class java.lang.ObjectCopyright © 1995–2018 Webtide. All rights reserved.