Class QueuedThreadPool

java.lang.Object
All Implemented Interfaces:
Executor, ThreadFactory, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, ThreadPool, ThreadPool.SizedThreadPool, TryExecutor, VirtualThreads.Configurable
Direct Known Subclasses:
MonitoredQueuedThreadPool

A thread pool with a queue of jobs to execute.

The queue of jobs should be unbounded, because critical jobs that have been submitted for execution cannot be rejected due to the queue bound limit. The queue might be temporarily full due to a job submission spike. Furthermore, the same HTTP request may be handled by different jobs, and would be non-optimal to reject a job of a request that is already being handled in favor of a job for a new concurrent request that is not yet handled by the application.

Jetty components that need threads (such as network acceptors and selector) may lease threads from this thread pool using a ThreadPoolBudget; these threads are "active" from the point of view of the thread pool, but not available to run unleased jobs such as processing an HTTP request or a WebSocket frame.

QueuedThreadPool has a ReservedThreadExecutor which leases threads from this pool to be used by the tryExecute(Runnable) method. This allows some key optimizations in the AdaptiveExecutionStrategy. The pool will avoid reserving new threads if there are jobs queued.

QueuedThreadPool has getters to take a snapshot of the following fundamental values:

  • threads: the current number of threads. These threads may execute a job (either internal or unleased), or may be ready to run (either idle or reserved). This number may grow or shrink as the thread pool grows or shrinks.
  • leasedThreads: the number of threads that may be needed to run internal jobs or be reserved for internal jobs. A pool should always be configured with more threads than the number of leased threads. This number is typically constant after this thread pool is started.
  • getCurrentReservedThreads(): the number of threads that have been reserved for #tryExecute(Runnable) jobs.
  • getIdleThreads(): the number of threads that are currently waiting for a job.
  • getQueueSize(): the number of jobs, queued waiting for a thread.

Given the definitions above, values derived from combinations of fundamental values include: