Package org.eclipse.jetty.util.thread
Class ReservedThreadExecutor
java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.thread.ReservedThreadExecutor
- All Implemented Interfaces:
- Executor,- Dumpable,- LifeCycle,- TryExecutor
@ManagedObject("A pool for reserved threads")
public class ReservedThreadExecutor
extends AbstractLifeCycle
implements TryExecutor, Dumpable
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.
- 
Nested Class SummaryNested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycleAbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.DumpableDumpable.DumpableContainerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycleLifeCycle.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.TryExecutorTryExecutor.NoTryExecutor
- 
Field SummaryFields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycleFAILED, STARTED, STARTING, STOPPED, STOPPINGFields inherited from interface org.eclipse.jetty.util.thread.TryExecutorNO_TRY
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoiddoStart()Method to override to start the lifecyclevoiddoStop()Method to override to stop the lifecyclevoiddump(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.voidintintlongintvoidsetIdleTimeout(long idleTime, TimeUnit idleTimeUnit) Set the idle timeout for shrinking the reserved thread pooltoString()booleantryExecute(Runnable task) Executes the given task if and only if a reserved thread is available.Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycleaddEventListener, getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, setEventListeners, start, stop
- 
Constructor Details- 
ReservedThreadExecutor- Parameters:
- 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.
 
 
- 
- 
Method Details- 
getExecutor
- 
getCapacity- Returns:
- the maximum number of reserved threads
 
- 
getAvailable- Returns:
- the number of threads available to tryExecute(Runnable)
 
- 
getPending
- 
getIdleTimeoutMs
- 
setIdleTimeoutSet the idle timeout for shrinking the reserved thread pool- Parameters:
- idleTime- Time to wait before shrinking, or 0 for default timeout.
- idleTimeUnit- Time units for idle timeout
 
- 
doStartDescription copied from class:AbstractLifeCycleMethod to override to start the lifecycle- Overrides:
- doStartin class- AbstractLifeCycle
- Throws:
- AbstractLifeCycle.StopException- If thrown, the lifecycle will immediately be stopped.
- Exception- If there was a problem starting. Will cause a transition to FAILED state
 
- 
doStopDescription copied from class:AbstractLifeCycleMethod to override to stop the lifecycle- Overrides:
- doStopin class- AbstractLifeCycle
- Throws:
- Exception- If there was a problem stopping. Will cause a transition to FAILED state
 
- 
execute- Specified by:
- executein interface- Executor
- Specified by:
- executein interface- TryExecutor
- Throws:
- RejectedExecutionException
 
- 
tryExecuteExecutes the given task if and only if a reserved thread is available. - Specified by:
- tryExecutein interface- TryExecutor
- Parameters:
- task- the task to run
- Returns:
- true if and only if a reserved thread was available and has been assigned the task to run.
 
- 
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.- Specified by:
- dumpin interface- Dumpable
- Parameters:
- out- The appendable to dump to
- indent- The indent to apply after any new lines.
- Throws:
- IOException- if unable to write to Appendable
 
- 
toString- Overrides:
- toStringin class- AbstractLifeCycle
 
 
-