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.

  • Constructor Details

    • ReservedThreadExecutor

      public ReservedThreadExecutor(Executor executor, int capacity)
      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