Top Description Inners Fields Constructors Methods
org.eclipse.jetty.util.thread

public Class QueuedThreadPool

extends ContainerLifeCycle
implements ThreadFactory, SizedThreadPool, Dumpable, TryExecutor, Configurable
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.VirtualThreads.Configurable, org.eclipse.jetty.util.thread.TryExecutor, java.util.concurrent.Executor, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool, org.eclipse.jetty.util.thread.ThreadPool, java.util.concurrent.ThreadFactory
Known Direct Subclasses
org.eclipse.jetty.util.thread.MonitoredQueuedThreadPool
Annotations
@ManagedObject:A thread pool
Imports
java.io.Closeable, .IOException, java.util.ArrayList, .List, .Set, java.util.concurrent.BlockingQueue, .ConcurrentHashMap, .Executor, .RejectedExecutionException, .ThreadFactory, .TimeUnit, java.util.concurrent.atomic.AtomicLong, org.eclipse.jetty.util.AtomicBiInteger, .BlockingArrayQueue, .NanoTime, .StringUtil, .VirtualThreads, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, .ManagedOperation, .Name, org.eclipse.jetty.util.component.ContainerLifeCycle, .Dumpable, .DumpableCollection, org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool, org.slf4j.Logger, .LoggerFactory

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:

Given the definitions above, the most interesting definitions are:

Other 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:

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private ThreadPoolBudget
private final AtomicBiInteger
_counts

Encodes thread counts:

Hi
Total thread count or Integer.MIN_VALUE if the pool is stopping
Lo
Net idle threads == idle threads - job queue size. Essentially if positive, this represents the effective number of idle threads, and if negative it represents the demand for more threads, which is equivalent to the job queue's size.
private boolean
private boolean
private final AtomicLong
private int
private final BlockingQueue<Runnable>
private final AutoLock.WithCondition
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<Thread>
private TryExecutor
private Executor
private static final Logger
private static final Runnable

Constructor Summary

AccessConstructor and Description
public
public
QueuedThreadPool(int maxThreads)

public
QueuedThreadPool(int maxThreads, int minThreads)

public
QueuedThreadPool(int maxThreads, int minThreads, BlockingQueue<Runnable> queue)

public
QueuedThreadPool(int maxThreads, int minThreads, int idleTimeout)

public
QueuedThreadPool(int maxThreads, int minThreads, int idleTimeout, BlockingQueue<Runnable> queue)

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)

Method Summary

Modifier and TypeMethod and Description
private boolean
addCounts(int deltaThreads, int deltaIdle)

protected void
doStart()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.

protected void
doStop()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

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.eclipse.jetty.util.component.ContainerLifeCycle.dump.

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Dump this object (and children) into an Appendable using the provided indent after any new lines.

public String
dumpThread(long
the thread ID to interrupt.
id
)

Returns: the stack frames dump

private void
protected boolean

Returns:

whether the current thread should be evicted
evict
()

Determines whether to evict the current thread from the pool.

public void
execute(Runnable
the runnable task
job
)

Overrides default org.eclipse.jetty.util.thread.TryExecutor.execute.

Implements java.util.concurrent.Executor.execute.

Executes the given command at some time in the future.

public int
getAvailableReservedThreads()

Returns: the number of available reserved threads

public int

Returns:

the number of threads executing internal and transient jobs
getBusyThreads
()

The number of threads executing internal and transient jobs.

private String
public int

Returns:

the number of idle threads but not reserved
getIdleThreads
()

Implements org.eclipse.jetty.util.thread.ThreadPool.getIdleThreads.

The number of idle threads, but without including reserved threads.

public int
getIdleTimeout()

Returns: the maximum thread idle time in ms

public int

Returns:

the number of threads currently used by internal components
getLeasedThreads
()

The 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 jobs
getMaxAvailableThreads
()

The maximum number of threads available to run transient jobs.

public int
getMaxEvictCount()

Returns: the maximum number of idle threads to evict in one idle timeout period

public int

Returns:

the maximum number of threads leased by internal components
getMaxLeasedThreads
()

The maximum number of threads that are leased to internal components, as some component may allocate its threads lazily.

public int
getMaxReservedThreads()

Returns: the maximum number (capacity) of reserved threads

public int
public int
public String
getName()

Returns: the name of the this thread pool

protected BlockingQueue<Runnable>
getQueue()

Returns: the job queue

public int
getQueueSize()

Returns: the number of jobs in the queue waiting for a thread

public int

Returns:

the number of threads ready to execute transient jobs
getReadyThreads
()

The fundamental value that represents the number of threads ready to execute transient jobs.

public int
getReservedThreads()

Returns: number of reserved threads or -1 for heuristically determined

public long
public ThreadPoolBudget
public int

Returns:

the number of threads currently known to the pool
getThreads
()

Implements org.eclipse.jetty.util.thread.ThreadPool.getThreads.

The fundamental value that represents the number of threads currently known by this thread pool.

public int
getThreadsPriority()

Returns: the priority of the pool threads

public double

Returns:

the utilization rate of threads executing transient jobs
getUtilizationRate
()

The rate between the number of utilized threads and the maximum number of utilizable threads.

public int

Returns:

the number of threads executing transient jobs
getUtilizedThreads
()

The 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
isDaemon()

Returns: whether to use daemon threads

public boolean
public boolean

Returns:

whether the pool is low on threads
isLowOnThreads
()

Implements org.eclipse.jetty.util.thread.ThreadPool.isLowOnThreads.

Returns whether this thread pool is low on threads.

public void
private void
joinThreads(long stopByNanos)

public Thread
newThread(Runnable
a runnable to be executed by new thread instance
runnable
)

Implements java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.

protected void
protected void
protected void
runJob(Runnable
the job to run
job
)

Runs the given job in the current thread.

public void
setDaemon(boolean
whether to use daemon threads
daemon
)

public void
setDetailedDump(boolean detailedDump)

public void
setIdleTimeout(int
the maximum thread idle time in ms
idleTimeout
)

Set the maximum thread idle time in ms.

public void
setLowThreadsThreshold(int lowThreadsThreshold)

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 minimum number of threads.

public void
setMaxThreads(int
the maximum number of threads
maxThreads
)

Implements org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool.setMaxThreads.

public void
public void
setName(String
the name of the this thread pool
name
)

Sets the name of this thread pool, used as a prefix for the thread names.

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
setStopTimeout(long stopTimeout)

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 to use to execute tasks in virtual threads
executor
)

Overrides default org.eclipse.jetty.util.VirtualThreads.Configurable.setVirtualThreadsExecutor.

protected void
public String
toString()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.toString.

Returns a string representation of the object.

public boolean
tryExecute(Runnable
The task to be executed
task
)

Implements org.eclipse.jetty.util.thread.TryExecutor.tryExecute.

Attempt to execute a task.

Inherited from org.eclipse.jetty.util.component.ContainerLifeCycle:
addBeanaddBeanaddEventListeneraddManagedcontainsdestroydumpdumpdumpObjectsdumpStdErrgetBeangetBeansgetBeansgetContainedBeansgetContainedBeansisAutoisManagedisUnmanagedmanageremoveBeanremoveBeansremoveEventListenersetBeansstartstopunmanageupdateBeanupdateBeanupdateBeansupdateBeans