Class QueuedThreadPool
- All Implemented Interfaces:
Executor
,ThreadFactory
,Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
,ThreadPool
,ThreadPool.SizedThreadPool
,TryExecutor
- Direct Known Subclasses:
MonitoredQueuedThreadPool
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 isstarted
.
Given the definitions above, the most interesting definitions are:
threads
=readyThreads
+leasedThreads
+utilizedThreads
- readyThreads =
idleThreads
+availableReservedThreads
maxAvailableThreads
=maxThreads
- leasedThreadsutilizationRate
= utilizedThreads / maxAvailableThreads
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:
busyThreads
= utilizedThreads + leasedThreadsgetIdleThreads()
idleThreads} = readyThreads - availableReservedThreads
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.ThreadPool
ThreadPool.SizedThreadPool
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.TryExecutor
TryExecutor.NoTryExecutor
-
Field Summary
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
Fields inherited from interface org.eclipse.jetty.util.thread.TryExecutor
NO_TRY
-
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.QueuedThreadPool
(int maxThreads) Deprecated.QueuedThreadPool
(int maxThreads, int minThreads) Deprecated.QueuedThreadPool
(int maxThreads, int minThreads, int idleTimeout) Deprecated.QueuedThreadPool
(int maxThreads, int minThreads, int idleTimeout, int reservedThreads, BlockingQueue<Runnable> queue, ThreadGroup threadGroup) Deprecated.QueuedThreadPool
(int maxThreads, int minThreads, int idleTimeout, int reservedThreads, BlockingQueue<Runnable> queue, ThreadGroup threadGroup, ThreadFactory threadFactory) Deprecated.QueuedThreadPool
(int maxThreads, int minThreads, int idleTimeout, BlockingQueue<Runnable> queue) Deprecated.QueuedThreadPool
(int maxThreads, int minThreads, int idleTimeout, BlockingQueue<Runnable> queue, ThreadGroup threadGroup) Deprecated.QueuedThreadPool
(int maxThreads, int minThreads, BlockingQueue<Runnable> queue) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoid
dump
(Appendable out, String indent) Deprecated.Dump this object (and children) into an Appendable using the provided indent after any new lines.dumpThread
(long id) Deprecated.void
Deprecated.int
Deprecated.int
Deprecated.The number of threads executing internal and transient jobs.int
Deprecated.The number of idle threads, but without including reserved threads.int
Deprecated.int
Deprecated.The fundamental value that represents the number of threads that are leased to internal components, and therefore cannot be used to execute transient jobs.int
Deprecated.int
Deprecated.The maximum number of threads available to run transient jobs.int
Deprecated.The maximum number of threads that are leased to internal components, as some component may allocate its threads lazily.int
Deprecated.int
Deprecated.int
Deprecated.getName()
Deprecated.int
Deprecated.int
Deprecated.The fundamental value that represents the number of threads ready to execute transient jobs.int
Deprecated.Deprecated.int
Deprecated.The fundamental value that represents the number of threads currently known by this thread pool.int
Deprecated.double
Deprecated.The rate between the number ofutilized threads
and the maximum number ofutilizable threads
.int
Deprecated.The number of threads executing transient jobs.boolean
interruptThread
(long id) Deprecated.boolean
isDaemon()
Deprecated.boolean
Deprecated.boolean
Deprecated.Returns whether this thread pool is low on threads.void
join()
Deprecated.Blocks until the thread pool isstopped
.Deprecated.void
setDaemon
(boolean daemon) Deprecated.void
setDetailedDump
(boolean detailedDump) Deprecated.void
setIdleTimeout
(int idleTimeout) Deprecated.Set the maximum thread idle time in ms.void
setLowThreadsThreshold
(int lowThreadsThreshold) Deprecated.void
setMaxThreads
(int maxThreads) Deprecated.void
setMinThreads
(int minThreads) Deprecated.void
Deprecated.Sets the name of this thread pool, used as a prefix for the thread names.void
setQueue
(BlockingQueue<Runnable> queue) Deprecated.pass the queue to the constructor insteadvoid
setReservedThreads
(int reservedThreads) Deprecated.void
setThreadPoolBudget
(ThreadPoolBudget budget) Deprecated.void
setThreadsPriority
(int priority) Deprecated.toString()
Deprecated.boolean
tryExecute
(Runnable task) Deprecated.Attempt to execute a task.Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, unmanage, updateBean, updateBean, updateBeans
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
Constructor Details
-
QueuedThreadPool
public QueuedThreadPool()Deprecated. -
QueuedThreadPool
Deprecated. -
QueuedThreadPool
Deprecated. -
QueuedThreadPool
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("queue") BlockingQueue<Runnable> queue) Deprecated. -
QueuedThreadPool
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout) Deprecated. -
QueuedThreadPool
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout, @Name("queue") BlockingQueue<Runnable> queue) Deprecated. -
QueuedThreadPool
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout, @Name("queue") BlockingQueue<Runnable> queue, @Name("threadGroup") ThreadGroup threadGroup) Deprecated. -
QueuedThreadPool
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout, @Name("reservedThreads") int reservedThreads, @Name("queue") BlockingQueue<Runnable> queue, @Name("threadGroup") ThreadGroup threadGroup) Deprecated. -
QueuedThreadPool
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout, @Name("reservedThreads") int reservedThreads, @Name("queue") BlockingQueue<Runnable> queue, @Name("threadGroup") ThreadGroup threadGroup, @Name("threadFactory") ThreadFactory threadFactory) Deprecated.
-
-
Method Details
-
getThreadPoolBudget
Deprecated.- Specified by:
getThreadPoolBudget
in interfaceThreadPool.SizedThreadPool
- Returns:
- a ThreadPoolBudget for this sized thread pool, or null of no ThreadPoolBudget can be returned
-
setThreadPoolBudget
Deprecated. -
getIdleTimeout
Deprecated.- Returns:
- the maximum thread idle time in ms
-
setIdleTimeout
public void setIdleTimeout(int idleTimeout) Deprecated.Set the maximum thread idle time in ms.
Threads that are idle for longer than this period may be stopped.
- Parameters:
idleTimeout
- the maximum thread idle time in ms
-
getMaxThreads
Deprecated.- Specified by:
getMaxThreads
in interfaceThreadPool.SizedThreadPool
- Returns:
- the maximum number of threads
-
setMaxThreads
public void setMaxThreads(int maxThreads) Deprecated.- Specified by:
setMaxThreads
in interfaceThreadPool.SizedThreadPool
- Parameters:
maxThreads
- the maximum number of threads
-
getMinThreads
Deprecated.- Specified by:
getMinThreads
in interfaceThreadPool.SizedThreadPool
- Returns:
- the minimum number of threads
-
setMinThreads
public void setMinThreads(int minThreads) Deprecated.- Specified by:
setMinThreads
in interfaceThreadPool.SizedThreadPool
- Parameters:
minThreads
- minimum number of threads
-
getReservedThreads
@ManagedAttribute("number of configured reserved threads or -1 for heuristic") public int getReservedThreads()Deprecated.- Returns:
- number of reserved threads or -1 for heuristically determined
-
setReservedThreads
public void setReservedThreads(int reservedThreads) Deprecated.- Parameters:
reservedThreads
- number of reserved threads or -1 for heuristically determined
-
getName
Deprecated.- Returns:
- the name of the this thread pool
-
setName
Deprecated.Sets the name of this thread pool, used as a prefix for the thread names.
- Parameters:
name
- the name of the this thread pool
-
getThreadsPriority
Deprecated.- Returns:
- the priority of the pool threads
-
setThreadsPriority
public void setThreadsPriority(int priority) Deprecated.- Parameters:
priority
- the priority of the pool threads
-
isDaemon
Deprecated.- Returns:
- whether to use daemon threads
- See Also:
-
setDaemon
public void setDaemon(boolean daemon) Deprecated.- Parameters:
daemon
- whether to use daemon threads- See Also:
-
isDetailedDump
Deprecated. -
setDetailedDump
public void setDetailedDump(boolean detailedDump) Deprecated. -
getLowThreadsThreshold
@ManagedAttribute("threshold at which the pool is low on threads") public int getLowThreadsThreshold()Deprecated. -
setLowThreadsThreshold
public void setLowThreadsThreshold(int lowThreadsThreshold) Deprecated. -
getQueueSize
Deprecated.- Returns:
- the number of jobs in the queue waiting for a thread
-
getMaxReservedThreads
@ManagedAttribute("maximum number (capacity) of reserved threads") public int getMaxReservedThreads()Deprecated.- Returns:
- the maximum number (capacity) of reserved threads
- See Also:
-
getAvailableReservedThreads
Deprecated.- Returns:
- the number of available reserved threads
- See Also:
-
getThreads
Deprecated.The fundamental value that represents the number of threads currently known by this thread pool.
This value includes threads that have been leased to internal components, idle threads, reserved threads and threads that are executing transient jobs.
- Specified by:
getThreads
in interfaceThreadPool
- Returns:
- the number of threads currently known to the pool
- See Also:
-
getReadyThreads
Deprecated.The fundamental value that represents the number of threads ready to execute transient jobs.
- Returns:
- the number of threads ready to execute transient jobs
- See Also:
-
getLeasedThreads
Deprecated.The fundamental value that represents the number of threads that are leased to internal components, and therefore cannot be used to execute transient jobs.
- Returns:
- the number of threads currently used by internal components
- See Also:
-
getMaxLeasedThreads
@ManagedAttribute("maximum number of threads leased to internal components") public int getMaxLeasedThreads()Deprecated.The maximum number of threads that are leased to internal components, as some component may allocate its threads lazily.
- Returns:
- the maximum number of threads leased by internal components
- See Also:
-
getIdleThreads
Deprecated.The number of idle threads, but without including reserved threads.
Prefer
getReadyThreads()
for a better representation of "threads ready to execute transient jobs".- Specified by:
getIdleThreads
in interfaceThreadPool
- Returns:
- the number of idle threads but not reserved
- See Also:
-
getBusyThreads
@ManagedAttribute("number of threads executing internal and transient jobs") public int getBusyThreads()Deprecated.The number of threads executing internal and transient jobs.
Prefer
getUtilizedThreads()
for a better representation of "threads executing transient jobs".- Returns:
- the number of threads executing internal and transient jobs
- See Also:
-
getUtilizedThreads
Deprecated.The number of threads executing transient jobs.
- Returns:
- the number of threads executing transient jobs
- See Also:
-
getMaxAvailableThreads
@ManagedAttribute("maximum number of threads available to run transient jobs") public int getMaxAvailableThreads()Deprecated.The maximum number of threads available to run transient jobs.
- Returns:
- the maximum number of threads available to run transient jobs
-
getUtilizationRate
@ManagedAttribute("utilization rate of threads executing transient jobs") public double getUtilizationRate()Deprecated.The rate between the number of
utilized threads
and the maximum number ofutilizable threads
.A value of
0.0D
means that the thread pool is not utilized, while a value of1.0D
means that the thread pool is fully utilized to execute transient jobs.- Returns:
- the utilization rate of threads executing transient jobs
-
isLowOnThreads
@ManagedAttribute(value="thread pool is low on threads", readonly=true) public boolean isLowOnThreads()Deprecated.Returns whether this thread pool is low on threads.
The current formula is:
maxThreads - threads + readyThreads - queueSize <= lowThreadsThreshold
- Specified by:
isLowOnThreads
in interfaceThreadPool
- Returns:
- whether the pool is low on threads
- See Also:
-
execute
Deprecated.- Specified by:
execute
in interfaceExecutor
- Specified by:
execute
in interfaceTryExecutor
-
tryExecute
Deprecated.Description copied from interface:TryExecutor
Attempt to execute a task.- Specified by:
tryExecute
in interfaceTryExecutor
- Parameters:
task
- The task to be executed- Returns:
- True IFF the task has been given directly to a thread to execute. The task cannot be queued pending the later availability of a Thread.
-
join
Deprecated.Blocks until the thread pool isstopped
.- Specified by:
join
in interfaceThreadPool
- Throws:
InterruptedException
- if thread was interrupted
-
newThread
Deprecated.- Specified by:
newThread
in interfaceThreadFactory
-
dump
Deprecated.Description copied from interface:Dumpable
Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.- Specified by:
dump
in interfaceDumpable
- Overrides:
dump
in classContainerLifeCycle
- Parameters:
out
- The appendable to dump toindent
- The indent to apply after any new lines.- Throws:
IOException
- if unable to write to Appendable
-
setQueue
Deprecated.pass the queue to the constructor instead- Parameters:
queue
- the job queue
-
interruptThread
Deprecated.- Parameters:
id
- the thread ID to interrupt.- Returns:
- true if the thread was found and interrupted.
-
dumpThread
Deprecated.- Parameters:
id
- the thread ID to interrupt.- Returns:
- the stack frames dump
-
toString
Deprecated.- Overrides:
toString
in classAbstractLifeCycle
-