@ManagedObject(value="A thread pool") public class QueuedThreadPool extends ContainerLifeCycle implements java.util.concurrent.ThreadFactory, ThreadPool.SizedThreadPool, Dumpable, TryExecutor
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 + leasedThreadsgetIdleThreads() idleThreads} = readyThreads - availableReservedThreadsAbstractLifeCycle.AbstractLifeCycleListenerThreadPool.SizedThreadPoolDumpable.DumpableContainerTryExecutor.NoTryExecutorContainer.InheritedListener, Container.ListenerLifeCycle.ListenerFAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPINGNO_TRY| Constructor and Description |
|---|
QueuedThreadPool() |
QueuedThreadPool(int maxThreads) |
QueuedThreadPool(int maxThreads,
int minThreads) |
QueuedThreadPool(int maxThreads,
int minThreads,
java.util.concurrent.BlockingQueue<java.lang.Runnable> queue) |
QueuedThreadPool(int maxThreads,
int minThreads,
int idleTimeout) |
QueuedThreadPool(int maxThreads,
int minThreads,
int idleTimeout,
java.util.concurrent.BlockingQueue<java.lang.Runnable> queue) |
QueuedThreadPool(int maxThreads,
int minThreads,
int idleTimeout,
java.util.concurrent.BlockingQueue<java.lang.Runnable> queue,
java.lang.ThreadGroup threadGroup) |
QueuedThreadPool(int maxThreads,
int minThreads,
int idleTimeout,
int reservedThreads,
java.util.concurrent.BlockingQueue<java.lang.Runnable> queue,
java.lang.ThreadGroup threadGroup) |
QueuedThreadPool(int maxThreads,
int minThreads,
int idleTimeout,
int reservedThreads,
java.util.concurrent.BlockingQueue<java.lang.Runnable> queue,
java.lang.ThreadGroup threadGroup,
java.util.concurrent.ThreadFactory threadFactory) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doStart()
Starts the managed lifecycle beans in the order they were added.
|
protected void |
doStop()
Stops the managed lifecycle beans in the reverse order they were added.
|
void |
dump(java.lang.Appendable out,
java.lang.String indent)
Dump this object (and children) into an Appendable using the provided indent after any new lines.
|
java.lang.String |
dumpThread(long id) |
void |
execute(java.lang.Runnable job) |
int |
getAvailableReservedThreads() |
int |
getBusyThreads()
The number of threads executing internal and transient jobs.
|
int |
getIdleThreads()
The number of idle threads, but without including reserved threads.
|
int |
getIdleTimeout() |
int |
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.
|
int |
getLowThreadsThreshold() |
int |
getMaxAvailableThreads()
The maximum number of threads available to run transient jobs.
|
int |
getMaxLeasedThreads()
The maximum number of threads that are leased to internal components,
as some component may allocate its threads lazily.
|
int |
getMaxReservedThreads() |
int |
getMaxThreads() |
int |
getMinThreads() |
java.lang.String |
getName() |
protected java.util.concurrent.BlockingQueue<java.lang.Runnable> |
getQueue() |
int |
getQueueSize() |
int |
getReadyThreads()
The fundamental value that represents the number of threads ready to execute transient jobs.
|
int |
getReservedThreads() |
ThreadPoolBudget |
getThreadPoolBudget() |
int |
getThreads()
The fundamental value that represents the number of threads currently known by this thread pool.
|
int |
getThreadsPriority() |
double |
getUtilizationRate()
The rate between the number of
utilized threads
and the maximum number of utilizable threads. |
int |
getUtilizedThreads()
The number of threads executing transient jobs.
|
boolean |
interruptThread(long id) |
boolean |
isDaemon() |
boolean |
isDetailedDump() |
boolean |
isLowOnThreads()
Returns whether this thread pool is low on threads.
|
void |
join()
Blocks until the thread pool is
stopped. |
java.lang.Thread |
newThread(java.lang.Runnable runnable) |
protected void |
removeThread(java.lang.Thread thread) |
protected void |
runJob(java.lang.Runnable job)
Runs the given job in the
current thread. |
void |
setDaemon(boolean daemon) |
void |
setDetailedDump(boolean detailedDump) |
void |
setIdleTimeout(int idleTimeout)
Set the maximum thread idle time in ms.
|
void |
setLowThreadsThreshold(int lowThreadsThreshold) |
void |
setMaxThreads(int maxThreads) |
void |
setMinThreads(int minThreads) |
void |
setName(java.lang.String name)
Sets the name of this thread pool, used as a prefix for the thread names.
|
void |
setQueue(java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
Deprecated.
pass the queue to the constructor instead
|
void |
setReservedThreads(int reservedThreads) |
void |
setThreadPoolBudget(ThreadPoolBudget budget) |
void |
setThreadsPriority(int priority) |
protected void |
startThread() |
java.lang.String |
toString() |
boolean |
tryExecute(java.lang.Runnable task)
Attempt to execute a task.
|
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeansaddLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stopclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitdump, dump, dumpContainer, dumpIterable, dumpMapEntries, dumpObject, dumpObjects, dumpSelf, namedasTryExecutorisDumpablepublic QueuedThreadPool()
public QueuedThreadPool(@Name(value="maxThreads") int maxThreads, @Name(value="minThreads") int minThreads)
public QueuedThreadPool(@Name(value="maxThreads") int maxThreads, @Name(value="minThreads") int minThreads, @Name(value="queue") java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
public QueuedThreadPool(@Name(value="maxThreads") int maxThreads, @Name(value="minThreads") int minThreads, @Name(value="idleTimeout") int idleTimeout)
public QueuedThreadPool(@Name(value="maxThreads") int maxThreads, @Name(value="minThreads") int minThreads, @Name(value="idleTimeout") int idleTimeout, @Name(value="queue") java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
public QueuedThreadPool(@Name(value="maxThreads") int maxThreads, @Name(value="minThreads") int minThreads, @Name(value="idleTimeout") int idleTimeout, @Name(value="queue") java.util.concurrent.BlockingQueue<java.lang.Runnable> queue, @Name(value="threadGroup") java.lang.ThreadGroup threadGroup)
public QueuedThreadPool(@Name(value="maxThreads") int maxThreads, @Name(value="minThreads") int minThreads, @Name(value="idleTimeout") int idleTimeout, @Name(value="reservedThreads") int reservedThreads, @Name(value="queue") java.util.concurrent.BlockingQueue<java.lang.Runnable> queue, @Name(value="threadGroup") java.lang.ThreadGroup threadGroup)
public QueuedThreadPool(@Name(value="maxThreads") int maxThreads, @Name(value="minThreads") int minThreads, @Name(value="idleTimeout") int idleTimeout, @Name(value="reservedThreads") int reservedThreads, @Name(value="queue") java.util.concurrent.BlockingQueue<java.lang.Runnable> queue, @Name(value="threadGroup") java.lang.ThreadGroup threadGroup, @Name(value="threadFactory") java.util.concurrent.ThreadFactory threadFactory)
public ThreadPoolBudget getThreadPoolBudget()
getThreadPoolBudget in interface ThreadPool.SizedThreadPoolpublic void setThreadPoolBudget(ThreadPoolBudget budget)
protected void doStart()
throws java.lang.Exception
ContainerLifeCycledoStart in class ContainerLifeCyclejava.lang.Exceptionprotected void doStop()
throws java.lang.Exception
ContainerLifeCycledoStop in class ContainerLifeCyclejava.lang.Exception@ManagedAttribute(value="maximum time a thread may be idle in ms") public int getIdleTimeout()
public void setIdleTimeout(int idleTimeout)
Set the maximum thread idle time in ms.
Threads that are idle for longer than this period may be stopped.
idleTimeout - the maximum thread idle time in ms@ManagedAttribute(value="maximum number of threads in the pool") public int getMaxThreads()
getMaxThreads in interface ThreadPool.SizedThreadPoolpublic void setMaxThreads(int maxThreads)
setMaxThreads in interface ThreadPool.SizedThreadPoolmaxThreads - the maximum number of threads@ManagedAttribute(value="minimum number of threads in the pool") public int getMinThreads()
getMinThreads in interface ThreadPool.SizedThreadPoolpublic void setMinThreads(int minThreads)
setMinThreads in interface ThreadPool.SizedThreadPoolminThreads - minimum number of threads@ManagedAttribute(value="number of configured reserved threads or -1 for heuristic") public int getReservedThreads()
public void setReservedThreads(int reservedThreads)
reservedThreads - number of reserved threads or -1 for heuristically determined@ManagedAttribute(value="name of the thread pool") public java.lang.String getName()
public void setName(java.lang.String name)
Sets the name of this thread pool, used as a prefix for the thread names.
name - the name of the this thread pool@ManagedAttribute(value="priority of threads in the pool") public int getThreadsPriority()
public void setThreadsPriority(int priority)
priority - the priority of the pool threads@ManagedAttribute(value="thread pool uses daemon threads") public boolean isDaemon()
Thread.isDaemon()public void setDaemon(boolean daemon)
daemon - whether to use daemon threadsThread.setDaemon(boolean)@ManagedAttribute(value="reports additional details in the dump") public boolean isDetailedDump()
public void setDetailedDump(boolean detailedDump)
@ManagedAttribute(value="threshold at which the pool is low on threads") public int getLowThreadsThreshold()
public void setLowThreadsThreshold(int lowThreadsThreshold)
@ManagedAttribute(value="size of the job queue") public int getQueueSize()
@ManagedAttribute(value="maximum number (capacity) of reserved threads") public int getMaxReservedThreads()
ReservedThreadExecutor.getCapacity()@ManagedAttribute(value="number of available reserved threads") public int getAvailableReservedThreads()
ReservedThreadExecutor.getAvailable()@ManagedAttribute(value="number of threads in the pool") public int getThreads()
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.
getThreads in interface ThreadPoolgetReadyThreads(),
getLeasedThreads()@ManagedAttribute(value="number of threads ready to execute transient jobs") public int getReadyThreads()
The fundamental value that represents the number of threads ready to execute transient jobs.
getThreads(),
getLeasedThreads(),
getUtilizedThreads()@ManagedAttribute(value="number of threads used by internal components") public int 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.
getThreads(),
getReadyThreads()@ManagedAttribute(value="maximum number of threads leased to internal components") public int getMaxLeasedThreads()
The maximum number of threads that are leased to internal components, as some component may allocate its threads lazily.
getLeasedThreads()@ManagedAttribute(value="number of idle threads but not reserved") public int getIdleThreads()
The number of idle threads, but without including reserved threads.
Prefer getReadyThreads() for a better representation of
"threads ready to execute transient jobs".
getIdleThreads in interface ThreadPoolgetReadyThreads()@ManagedAttribute(value="number of threads executing internal and transient jobs") public int getBusyThreads()
The number of threads executing internal and transient jobs.
Prefer getUtilizedThreads() for a better representation of
"threads executing transient jobs".
getUtilizedThreads()@ManagedAttribute(value="number of threads executing transient jobs") public int getUtilizedThreads()
The number of threads executing transient jobs.
getReadyThreads()@ManagedAttribute(value="maximum number of threads available to run transient jobs") public int getMaxAvailableThreads()
The maximum number of threads available to run transient jobs.
@ManagedAttribute(value="utilization rate of threads executing transient jobs") public double getUtilizationRate()
The rate between the number of utilized threads
and the maximum number of utilizable threads.
A value of 0.0D means that the thread pool is not utilized, while a
value of 1.0D means that the thread pool is fully utilized to execute
transient jobs.
@ManagedAttribute(value="thread pool is low on threads", readonly=true) public boolean isLowOnThreads()
Returns whether this thread pool is low on threads.
The current formula is:
maxThreads - threads + readyThreads - queueSize <= lowThreadsThreshold
isLowOnThreads in interface ThreadPoolgetLowThreadsThreshold()public void execute(java.lang.Runnable job)
execute in interface java.util.concurrent.Executorexecute in interface TryExecutorpublic boolean tryExecute(java.lang.Runnable task)
TryExecutortryExecute in interface TryExecutortask - The task to be executedpublic void join()
throws java.lang.InterruptedException
stopped.join in interface ThreadPooljava.lang.InterruptedException - if thread was interruptedprotected void startThread()
public java.lang.Thread newThread(java.lang.Runnable runnable)
newThread in interface java.util.concurrent.ThreadFactoryprotected void removeThread(java.lang.Thread thread)
public void dump(java.lang.Appendable out,
java.lang.String indent)
throws java.io.IOException
Dumpabledump in interface Dumpabledump in class ContainerLifeCycleout - The appendable to dump toindent - The indent to apply after any new lines.java.io.IOException - if unable to write to Appendableprotected void runJob(java.lang.Runnable job)
Runs the given job in the current thread.
Subclasses may override to perform pre/post actions before/after the job is run.
job - the job to runprotected java.util.concurrent.BlockingQueue<java.lang.Runnable> getQueue()
@Deprecated public void setQueue(java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
queue - the job queue@ManagedOperation(value="interrupts a pool thread") public boolean interruptThread(@Name(value="id") long id)
id - the thread ID to interrupt.@ManagedOperation(value="dumps a pool thread stack") public java.lang.String dumpThread(@Name(value="id") long id)
id - the thread ID to interrupt.public java.lang.String toString()
toString in class AbstractLifeCycleCopyright © 1995–2021 Webtide. All rights reserved.