- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.util.thread.QueuedThreadPool
-
- All Implemented Interfaces:
java.util.concurrent.Executor,java.util.concurrent.ThreadFactory,Container,Destroyable,Dumpable,LifeCycle,ThreadPool,ThreadPool.SizedThreadPool,TryExecutor
- Direct Known Subclasses:
MonitoredQueuedThreadPool
@ManagedObject("A thread pool") public class QueuedThreadPool extends ContainerLifeCycle implements java.util.concurrent.ThreadFactory, ThreadPool.SizedThreadPool, Dumpable, TryExecutor
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopException
-
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.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, STARTED, STARTING, STOPPED, STOPPING
-
Fields inherited from interface org.eclipse.jetty.util.thread.TryExecutor
NO_TRY
-
-
Constructor Summary
Constructors Constructor Description QueuedThreadPool()QueuedThreadPool(int maxThreads)QueuedThreadPool(int maxThreads, int minThreads)QueuedThreadPool(int maxThreads, int minThreads, int idleTimeout)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)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, java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoStart()Starts the managed lifecycle beans in the order they were added.protected voiddoStop()Stops the managed lifecycle beans in the reverse order they were added.voiddump(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.StringdumpThread(long id)voidexecute(java.lang.Runnable job)intgetBusyThreads()intgetIdleThreads()intgetIdleTimeout()Get the maximum thread idle time.intgetLowThreadsThreshold()intgetMaxThreads()Get the maximum number of threads.intgetMinThreads()Get the minimum number of threads.java.lang.StringgetName()protected java.util.concurrent.BlockingQueue<java.lang.Runnable>getQueue()intgetQueueSize()Get the size of the job queue.intgetReservedThreads()Get the number of reserved threads.longgetStopTimeout()ThreadPoolBudgetgetThreadPoolBudget()intgetThreads()intgetThreadsPriority()Get the priority of the pool threads.booleaninterruptThread(long id)booleanisDaemon()booleanisDetailedDump()booleanisLowOnThreads()Returns whether this thread pool is low on threads.voidjoin()Blocks until the thread pool isLifeCyclestopped.java.lang.ThreadnewThread(java.lang.Runnable runnable)protected voidremoveThread(java.lang.Thread thread)protected voidrunJob(java.lang.Runnable job)Runs the given job in thecurrent thread.voidsetDaemon(boolean daemon)Thread Pool should use Daemon Threading.voidsetDetailedDump(boolean detailedDump)voidsetIdleTimeout(int idleTimeout)Set the maximum thread idle time.voidsetLowThreadsThreshold(int lowThreadsThreshold)voidsetMaxThreads(int maxThreads)Set the maximum number of threads.voidsetMinThreads(int minThreads)Set the minimum number of threads.voidsetName(java.lang.String name)voidsetReservedThreads(int reservedThreads)Set the number of reserved threads.voidsetStopTimeout(long stopTimeout)voidsetThreadPoolBudget(ThreadPoolBudget budget)voidsetThreadsPriority(int priority)Set the priority of the pool threads.protected voidstartThread()java.lang.StringtoString()booleantryExecute(java.lang.Runnable task)Attempt to execute a task.-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListeners
-
-
-
-
Constructor Detail
-
QueuedThreadPool
public QueuedThreadPool()
-
QueuedThreadPool
public QueuedThreadPool(@Name("maxThreads") int maxThreads)
-
QueuedThreadPool
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads)
-
QueuedThreadPool
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("queue") java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
-
QueuedThreadPool
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout)
-
QueuedThreadPool
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout, @Name("queue") java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
-
QueuedThreadPool
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout, @Name("queue") java.util.concurrent.BlockingQueue<java.lang.Runnable> queue, @Name("threadGroup") java.lang.ThreadGroup threadGroup)
-
QueuedThreadPool
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout, @Name("reservedThreads") int reservedThreads, @Name("queue") java.util.concurrent.BlockingQueue<java.lang.Runnable> queue, @Name("threadGroup") java.lang.ThreadGroup threadGroup)
-
QueuedThreadPool
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout, @Name("reservedThreads") int reservedThreads, @Name("queue") java.util.concurrent.BlockingQueue<java.lang.Runnable> queue, @Name("threadGroup") java.lang.ThreadGroup threadGroup, @Name("threadFactory") java.util.concurrent.ThreadFactory threadFactory)
-
-
Method Detail
-
getThreadPoolBudget
public ThreadPoolBudget getThreadPoolBudget()
- Specified by:
getThreadPoolBudgetin interfaceThreadPool.SizedThreadPool- Returns:
- a ThreadPoolBudget for this sized thread pool, or null of no ThreadPoolBudget can be returned
-
setThreadPoolBudget
public void setThreadPoolBudget(ThreadPoolBudget budget)
-
setStopTimeout
public void setStopTimeout(long stopTimeout)
-
getStopTimeout
public long getStopTimeout()
-
doStart
protected void doStart() throws java.lang.ExceptionDescription copied from class:ContainerLifeCycleStarts the managed lifecycle beans in the order they were added.- Overrides:
doStartin classContainerLifeCycle- Throws:
AbstractLifeCycle.StopException- If thrown, the lifecycle will immediately be stopped.java.lang.Exception- If there was a problem starting. Will cause a transition to FAILED state
-
doStop
protected void doStop() throws java.lang.ExceptionDescription copied from class:ContainerLifeCycleStops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStopin classContainerLifeCycle- Throws:
java.lang.Exception- If there was a problem stopping. Will cause a transition to FAILED state
-
setDaemon
public void setDaemon(boolean daemon)
Thread Pool should use Daemon Threading.- Parameters:
daemon- true to enable delegation- See Also:
Thread.setDaemon(boolean)
-
setIdleTimeout
public void setIdleTimeout(int idleTimeout)
Set the maximum thread idle time. Threads that are idle for longer than this period may be stopped.- Parameters:
idleTimeout- Max idle time in ms.- See Also:
getIdleTimeout()
-
setMaxThreads
public void setMaxThreads(int maxThreads)
Set the maximum number of threads.- Specified by:
setMaxThreadsin interfaceThreadPool.SizedThreadPool- Parameters:
maxThreads- maximum number of threads.- See Also:
getMaxThreads()
-
setMinThreads
public void setMinThreads(int minThreads)
Set the minimum number of threads.- Specified by:
setMinThreadsin interfaceThreadPool.SizedThreadPool- Parameters:
minThreads- minimum number of threads- See Also:
getMinThreads()
-
setReservedThreads
public void setReservedThreads(int reservedThreads)
Set the number of reserved threads.- Parameters:
reservedThreads- number of reserved threads or -1 for heuristically determined- See Also:
getReservedThreads()
-
setName
public void setName(java.lang.String name)
- Parameters:
name- Name of this thread pool to use when naming threads.
-
setThreadsPriority
public void setThreadsPriority(int priority)
Set the priority of the pool threads.- Parameters:
priority- the new thread priority.
-
getIdleTimeout
@ManagedAttribute("maximum time a thread may be idle in ms") public int getIdleTimeout()
Get the maximum thread idle time.- Returns:
- Max idle time in ms.
- See Also:
setIdleTimeout(int)
-
getMaxThreads
@ManagedAttribute("maximum number of threads in the pool") public int getMaxThreads()
Get the maximum number of threads.- Specified by:
getMaxThreadsin interfaceThreadPool.SizedThreadPool- Returns:
- maximum number of threads.
- See Also:
setMaxThreads(int)
-
getMinThreads
@ManagedAttribute("minimum number of threads in the pool") public int getMinThreads()
Get the minimum number of threads.- Specified by:
getMinThreadsin interfaceThreadPool.SizedThreadPool- Returns:
- minimum number of threads.
- See Also:
setMinThreads(int)
-
getReservedThreads
@ManagedAttribute("the number of reserved threads in the pool") public int getReservedThreads()
Get the number of reserved threads.- Returns:
- number of reserved threads or or -1 for heuristically determined
- See Also:
setReservedThreads(int)
-
getName
@ManagedAttribute("name of the thread pool") public java.lang.String getName()
- Returns:
- The name of the this thread pool
-
getThreadsPriority
@ManagedAttribute("priority of threads in the pool") public int getThreadsPriority()
Get the priority of the pool threads.- Returns:
- the priority of the pool threads.
-
getQueueSize
@ManagedAttribute("size of the job queue") public int getQueueSize()
Get the size of the job queue.- Returns:
- Number of jobs queued waiting for a thread
-
isDaemon
@ManagedAttribute("thread pool uses daemon threads") public boolean isDaemon()
- Returns:
- whether this thread pool is using daemon threads
- See Also:
Thread.setDaemon(boolean)
-
isDetailedDump
@ManagedAttribute("reports additional details in the dump") public boolean isDetailedDump()
-
setDetailedDump
public void setDetailedDump(boolean detailedDump)
-
getLowThreadsThreshold
@ManagedAttribute("threshold at which the pool is low on threads") public int getLowThreadsThreshold()
-
setLowThreadsThreshold
public void setLowThreadsThreshold(int lowThreadsThreshold)
-
execute
public void execute(java.lang.Runnable job)
- Specified by:
executein interfacejava.util.concurrent.Executor- Specified by:
executein interfaceTryExecutor
-
tryExecute
public boolean tryExecute(java.lang.Runnable task)
Description copied from interface:TryExecutorAttempt to execute a task.- Specified by:
tryExecutein 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
public void join() throws java.lang.InterruptedExceptionBlocks until the thread pool isLifeCyclestopped.- Specified by:
joinin interfaceThreadPool- Throws:
java.lang.InterruptedException- if thread was interrupted
-
getThreads
@ManagedAttribute("number of threads in the pool") public int getThreads()
- Specified by:
getThreadsin interfaceThreadPool- Returns:
- the total number of threads currently in the pool
-
getIdleThreads
@ManagedAttribute("number of idle threads in the pool") public int getIdleThreads()
- Specified by:
getIdleThreadsin interfaceThreadPool- Returns:
- the number of idle threads in the pool
-
getBusyThreads
@ManagedAttribute("number of busy threads in the pool") public int getBusyThreads()
- Returns:
- the number of busy threads in the pool
-
isLowOnThreads
@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 + idleThreads - queueSize <= lowThreadsThreshold
- Specified by:
isLowOnThreadsin interfaceThreadPool- Returns:
- whether the pool is low on threads
- See Also:
getLowThreadsThreshold()
-
startThread
protected void startThread()
-
newThread
public java.lang.Thread newThread(java.lang.Runnable runnable)
- Specified by:
newThreadin interfacejava.util.concurrent.ThreadFactory
-
removeThread
protected void removeThread(java.lang.Thread thread)
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOExceptionDescription copied from interface:DumpableDump 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:
dumpin interfaceDumpable- Overrides:
dumpin classContainerLifeCycle- Parameters:
out- The appendable to dump toindent- The indent to apply after any new lines.- Throws:
java.io.IOException- if unable to write to Appendable
-
toString
public java.lang.String toString()
- Overrides:
toStringin classAbstractLifeCycle
-
runJob
protected 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.
- Parameters:
job- the job to run
-
getQueue
protected java.util.concurrent.BlockingQueue<java.lang.Runnable> getQueue()
- Returns:
- the job queue
-
interruptThread
@ManagedOperation("interrupts a pool thread") public boolean interruptThread(@Name("id") long id)
- Parameters:
id- the thread ID to interrupt.- Returns:
- true if the thread was found and interrupted.
-
dumpThread
@ManagedOperation("dumps a pool thread stack") public java.lang.String dumpThread(@Name("id") long id)
- Parameters:
id- the thread ID to interrupt.- Returns:
- the stack frames dump
-
-