A thread pool with a queue of jobs to execute.
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 transient jobs such as processing
an HTTP request or a WebSocket frame.
QueuedThreadPool has a ReservedThreadExecutor which leases threads from this pool,
but makes them available as if they are "idle" threads.
QueuedThreadPool therefore has the following fundamental values:
threads: the current number of threads. These threads may execute
a job (either internal or transient), or may be ready to run (either idle or reserved).
This number may grow or shrink as the thread pool grows or shrinks.readyThreads: the current number of threads that are ready to
run transient jobs.
This number may grow or shrink as the thread pool grows or shrinks.leasedThreads: the number of threads that run internal jobs.
This number is typically constant after this thread pool is started.Given the definitions above, the most interesting definitions are:
threads = readyThreads + leasedThreads + utilizedThreadsidleThreads + availableReservedThreadsmaxAvailableThreads = maxThreads - leasedThreadsutilizationRate = utilizedThreads / maxAvailableThreadsOther definitions, typically less interesting because they take into account threads that execute internal jobs, or because they don't take into account available reserved threads (that are essentially ready to execute transient jobs), are:
busyThreads = utilizedThreads + leasedThreadsidleThreads = readyThreads - availableReservedThreads| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private ThreadPoolBudget | |
| private final AtomicBiInteger | _counts
Encodes thread counts:
|
| private boolean | |
| private boolean | |
| private final AtomicLong | |
| private int | |
| private final BlockingQueue | |
| private final AutoLock. | |
| private int | |
| private int | |
| private int | |
| private int | |
| private String | |
| private int | |
| private int | |
| private final Runnable | |
| private long | |
| private final ThreadFactory | |
| private final ThreadGroup | |
| private final Set | |
| private TryExecutor | |
| private Executor | |
| private static final Logger | |
| private static final Runnable |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | |
| public | |
| public | |
| public | |
| public | QueuedThreadPool(int maxThreads, int minThreads, int idleTimeout, BlockingQueue<Runnable> queue, ThreadGroup threadGroup)
|
| public | QueuedThreadPool(int maxThreads, int minThreads, int idleTimeout, int reservedThreads, BlockingQueue<Runnable> queue, ThreadGroup threadGroup)
|
| public | QueuedThreadPool(int maxThreads, int minThreads, int idleTimeout, int reservedThreads, BlockingQueue<Runnable> queue, ThreadGroup threadGroup, ThreadFactory threadFactory)
|
| Modifier and Type | Method and Description |
|---|---|
| private boolean | |
| protected void | doStart()
Overrides org. Starts the managed lifecycle beans in the order they were added. |
| protected void | doStop()
Overrides org. Stops the managed lifecycle beans in the reverse order they were added. |
| public void | dump(Appendable
The appendable to dump to out, String The indent to apply after any new lines. indent)Overrides org. Implements org. Dump this object (and children) into an Appendable using the provided indent after any new lines. |
| public String | |
| private void | |
| protected boolean | Returns: whether the current thread should be evictedDetermines whether to evict the current thread from the pool. |
| public void | execute(Runnable
the runnable task job)Overrides default org. Implements java. Executes the given command at some time in the future. |
| public int | |
| public int | Returns: the number of threads executing internal and transient jobsThe number of threads executing internal and transient jobs. |
| private String | |
| public int | Returns: the number of idle threads but not reservedImplements org. The number of idle threads, but without including reserved threads. |
| public int | |
| public int | Returns: the number of threads currently used by internal componentsThe fundamental value that represents the number of threads that are leased to internal components, and therefore cannot be used to execute transient jobs. |
| public int | |
| public int | Returns: the maximum number of threads available to run transient jobsThe maximum number of threads available to run transient jobs. |
| public int | |
| public int | Returns: the maximum number of threads leased by internal componentsThe maximum number of threads that are leased to internal components, as some component may allocate its threads lazily. |
| public int | |
| public int | getMaxThreads()
Implements org. Returns: the maximum number of threads |
| public int | getMinThreads()
Implements org. Returns: the minimum number of threads |
| public String | |
| protected BlockingQueue | |
| public int | |
| public int | Returns: the number of threads ready to execute transient jobsThe fundamental value that represents the number of threads ready to execute transient jobs. |
| public int | |
| public long | |
| public ThreadPoolBudget | |
| public int | Returns: the number of threads currently known to the poolImplements org. The fundamental value that represents the number of threads currently known by this thread pool. |
| public int | |
| public double | Returns: the utilization rate of threads executing transient jobsThe rate between the number of |
| public int | Returns: the number of threads executing transient jobsThe number of threads executing transient jobs. |
| public Executor | |
| public boolean | interruptThread(long
the thread ID to interrupt. id)Returns: true if the thread was found and interrupted. |
| public boolean | |
| public boolean | |
| public boolean | Returns: whether the pool is low on threadsImplements org. Returns whether this thread pool is low on threads. |
| public void | join()
Implements org. Blocks until the thread pool is |
| private void | |
| public Thread | newThread(Runnable
a runnable to be executed by new thread instance runnable)Implements java. Constructs a new unstarted |
| protected void | |
| protected void | |
| protected void | |
| public void | |
| public void | |
| public void | setIdleTimeout(int
the maximum thread idle time in ms idleTimeout)Set the maximum thread idle time in ms. |
| public void | |
| public void | setMaxEvictCount(int
the maximum number of idle threads to evict in one idle timeout period evictCount)Returns the maximum number of idle threads that are evicted for every idle timeout
period, thus shrinking this thread pool towards its |
| public void | setMaxThreads(int
the maximum number of threads maxThreads)Implements org.
|
| public void | setMinThreads(int
minimum number of threads minThreads)Implements org.
|
| public void | |
| public void | setReservedThreads(int
number of reserved threads or -1 for heuristically determined reservedThreads)Set number of reserved threads or -1 for heuristically determined. |
| public void | |
| public void | |
| public void | setThreadsPriority(int
the priority of the pool threads priority)Set the priority of the pool threads. |
| public void | setVirtualThreadsExecutor(Executor
the executor)Executor to use to execute tasks in virtual threadsOverrides default org.
|
| protected void | |
| public String | toString()
Overrides org. Returns a string representation of the object. |
| public boolean | tryExecute(Runnable
The task to be executed task)Implements org. Attempt to execute a task. |