Package org.eclipse.jetty.util.thread
Class ExecutorThreadPool
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.util.thread.ExecutorThreadPool
-
- All Implemented Interfaces:
java.util.concurrent.Executor,Container,Destroyable,Dumpable,Dumpable.DumpableContainer,LifeCycle,ThreadPool,ThreadPool.SizedThreadPool,TryExecutor
- Direct Known Subclasses:
ExecutorSizedThreadPool
@ManagedObject("A thread pool") public class ExecutorThreadPool extends ContainerLifeCycle implements ThreadPool.SizedThreadPool, TryExecutor
AThreadPool.SizedThreadPoolwrapper aroundThreadPoolExecutor.
-
-
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
Constructors Constructor Description ExecutorThreadPool()ExecutorThreadPool(int maxThreads)ExecutorThreadPool(int maxThreads, int minThreads)ExecutorThreadPool(int maxThreads, int minThreads, java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)ExecutorThreadPool(java.util.concurrent.ThreadPoolExecutor executor)ExecutorThreadPool(java.util.concurrent.ThreadPoolExecutor executor, int reservedThreads)ExecutorThreadPool(java.util.concurrent.ThreadPoolExecutor executor, int reservedThreads, java.lang.ThreadGroup group)
-
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.voidexecute(java.lang.Runnable command)intgetIdleThreads()intgetIdleTimeout()intgetMaxThreads()intgetMinThreads()java.lang.StringgetName()intgetReservedThreads()ThreadPoolBudgetgetThreadPoolBudget()intgetThreads()intgetThreadsPriority()booleanisDaemon()booleanisDetailedDump()booleanisLowOnThreads()voidjoin()Blocks until the thread pool isstopped.protected java.lang.ThreadnewThread(java.lang.Runnable job)voidsetDaemon(boolean daemon)voidsetDetailedDump(boolean detailedDump)voidsetIdleTimeout(int idleTimeout)Sets the maximum thread idle time in ms.voidsetMaxThreads(int threads)voidsetMinThreads(int threads)voidsetName(java.lang.String name)voidsetReservedThreads(int reservedThreads)Sets the number of reserved threads.voidsetThreadsPriority(int priority)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, 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, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
-
-
-
Constructor Detail
-
ExecutorThreadPool
public ExecutorThreadPool()
-
ExecutorThreadPool
public ExecutorThreadPool(int maxThreads)
-
ExecutorThreadPool
public ExecutorThreadPool(int maxThreads, int minThreads)
-
ExecutorThreadPool
public ExecutorThreadPool(int maxThreads, int minThreads, java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
-
ExecutorThreadPool
public ExecutorThreadPool(java.util.concurrent.ThreadPoolExecutor executor)
-
ExecutorThreadPool
public ExecutorThreadPool(java.util.concurrent.ThreadPoolExecutor executor, int reservedThreads)
-
ExecutorThreadPool
public ExecutorThreadPool(java.util.concurrent.ThreadPoolExecutor executor, int reservedThreads, java.lang.ThreadGroup group)
-
-
Method Detail
-
getName
@ManagedAttribute("name of this thread pool") public java.lang.String getName()
- Returns:
- the name of the this thread pool
-
setName
public void setName(java.lang.String name)
- Parameters:
name- the name of this thread pool, used to name threads
-
getMinThreads
@ManagedAttribute("minimum number of threads in the pool") public int getMinThreads()
- Specified by:
getMinThreadsin interfaceThreadPool.SizedThreadPool- Returns:
- the minimum number of threads
-
setMinThreads
public void setMinThreads(int threads)
- Specified by:
setMinThreadsin interfaceThreadPool.SizedThreadPool- Parameters:
threads- the minimum number of threads
-
getMaxThreads
@ManagedAttribute("maximum number of threads in the pool") public int getMaxThreads()
- Specified by:
getMaxThreadsin interfaceThreadPool.SizedThreadPool- Returns:
- the maximum number of threads
-
setMaxThreads
public void setMaxThreads(int threads)
- Specified by:
setMaxThreadsin interfaceThreadPool.SizedThreadPool- Parameters:
threads- the maximum number of threads
-
getIdleTimeout
@ManagedAttribute("maximum time a thread may be idle in ms") public int getIdleTimeout()
- Returns:
- the maximum thread idle time in ms.
- See Also:
setIdleTimeout(int)
-
setIdleTimeout
public void setIdleTimeout(int idleTimeout)
Sets 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.- See Also:
getIdleTimeout()
-
getReservedThreads
@ManagedAttribute("the number of reserved threads in the pool") public int getReservedThreads()
- Returns:
- number of reserved threads or -1 to indicate that the number is heuristically determined
- See Also:
setReservedThreads(int)
-
setReservedThreads
public void setReservedThreads(int reservedThreads)
Sets the number of reserved threads.- Parameters:
reservedThreads- number of reserved threads or -1 to determine the number heuristically- See Also:
getReservedThreads()
-
setThreadsPriority
public void setThreadsPriority(int priority)
-
getThreadsPriority
public int getThreadsPriority()
-
isDaemon
@ManagedAttribute("whether this thread pool uses daemon threads") public boolean isDaemon()
- Returns:
- whether this thread pool uses daemon threads
- See Also:
setDaemon(boolean)
-
setDaemon
public void setDaemon(boolean daemon)
- Parameters:
daemon- whether this thread pool uses daemon threads- See Also:
Thread.setDaemon(boolean)
-
isDetailedDump
@ManagedAttribute("reports additional details in the dump") public boolean isDetailedDump()
-
setDetailedDump
public void setDetailedDump(boolean detailedDump)
-
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
-
execute
public void execute(java.lang.Runnable command)
- 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.
-
isLowOnThreads
@ManagedAttribute(value="thread pool is low on threads", readonly=true) public boolean isLowOnThreads()
- Specified by:
isLowOnThreadsin interfaceThreadPool- Returns:
- True if the pool is low on threads
-
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:
java.lang.Exception
-
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
-
join
public void join() throws java.lang.InterruptedExceptionDescription copied from interface:ThreadPoolBlocks until the thread pool isstopped.- Specified by:
joinin interfaceThreadPool- Throws:
java.lang.InterruptedException- if thread was interrupted
-
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
-
newThread
protected java.lang.Thread newThread(java.lang.Runnable job)
-
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
-
-