A TryExecutor using pre-allocated/reserved threads from an external Executor.
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.
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, STARTED, STARTING, STOPPED, STOPPING
Method SummaryModifier and TypeMethodDescription
doStart()Method to override to start the lifecycle
doStop()Method to override to stop the lifecycle
voidDump this object (and children) into an Appendable using the provided indent after any new lines.
voidSet the idle timeout for shrinking the reserved thread pool
booleanExecutes the given task if and only if a reserved thread is available.
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addEventListener, getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, setEventListeners, start, stop
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
(Executor executor, int capacity)
executor- The executor to use to obtain threads
capacity- 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.
getExecutorpublic Executor getExecutor()
- the maximum number of reserved threads
- the number of threads available to
setIdleTimeoutpublic void setIdleTimeout
(long idleTime, TimeUnit idleTimeUnit)Set the idle timeout for shrinking the reserved thread pool
idleTime- Time to wait before shrinking, or 0 for default timeout.
idleTimeUnit- Time units for idle timeout
doStartpublic void doStart() throws ExceptionDescription copied from class:
AbstractLifeCycleMethod to override to start the lifecycle
doStoppublic void doStop() throws ExceptionDescription copied from class:
AbstractLifeCycleMethod to override to stop the lifecycle
tryExecutepublic boolean tryExecute
Executes the given task if and only if a reserved thread is available.
dumpDescription copied from interface:
DumpableDump 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.
toStringpublic String toString()