Class ReservedThreadExecutor

  • All Implemented Interfaces:
    Executor, LifeCycle, TryExecutor

    @ManagedObject("A pool for reserved threads")
    public class ReservedThreadExecutor
    extends AbstractLifeCycle
    implements TryExecutor
    The Eclipse Jetty and Apache Felix Http Jetty packages are no longer supported.
    An Executor using preallocated/reserved Threads from a wrapped Executor.

    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.

    • Constructor Detail

      • ReservedThreadExecutor

        public ReservedThreadExecutor​(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.