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:
Executor
,Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
,ThreadPool
,ThreadPool.SizedThreadPool
,TryExecutor
,VirtualThreads.Configurable
@ManagedObject("A thread pool")
public class ExecutorThreadPool
extends ContainerLifeCycle
implements ThreadPool.SizedThreadPool, TryExecutor, VirtualThreads.Configurable
A
ThreadPool.SizedThreadPool
wrapper around ThreadPoolExecutor
.-
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.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, STARTED, STARTING, STOPPED, STOPPING
Fields inherited from interface org.eclipse.jetty.util.thread.TryExecutor
NO_TRY
-
Constructor Summary
ConstructorDescriptionExecutorThreadPool
(int maxThreads) ExecutorThreadPool
(int maxThreads, int minThreads) ExecutorThreadPool
(int maxThreads, int minThreads, BlockingQueue<Runnable> queue) ExecutorThreadPool
(ThreadPoolExecutor executor) ExecutorThreadPool
(ThreadPoolExecutor executor, int reservedThreads) ExecutorThreadPool
(ThreadPoolExecutor executor, int reservedThreads, ThreadGroup group) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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
(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.void
int
int
int
int
getName()
int
int
int
boolean
isDaemon()
boolean
boolean
void
join()
Blocks until the thread pool isstopped
.protected Thread
void
setDaemon
(boolean daemon) void
setDetailedDump
(boolean detailedDump) void
setIdleTimeout
(int idleTimeout) Sets the maximum thread idle time in ms.void
setMaxThreads
(int threads) void
setMinThreads
(int threads) void
void
setReservedThreads
(int reservedThreads) Sets the number of reserved threads.void
setThreadsPriority
(int priority) void
setVirtualThreadsExecutor
(Executor executor) toString()
boolean
tryExecute
(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, 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
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
Methods inherited from interface org.eclipse.jetty.util.VirtualThreads.Configurable
isUseVirtualThreads, setUseVirtualThreads
-
Constructor Details
-
ExecutorThreadPool
public ExecutorThreadPool() -
ExecutorThreadPool
public ExecutorThreadPool(int maxThreads) -
ExecutorThreadPool
public ExecutorThreadPool(int maxThreads, int minThreads) -
ExecutorThreadPool
-
ExecutorThreadPool
-
ExecutorThreadPool
-
ExecutorThreadPool
-
-
Method Details
-
getName
- Returns:
- the name of the this thread pool
-
setName
- Parameters:
name
- the name of this thread pool, used to name threads
-
getMinThreads
- Specified by:
getMinThreads
in interfaceThreadPool.SizedThreadPool
- Returns:
- the minimum number of threads
-
setMinThreads
public void setMinThreads(int threads) - Specified by:
setMinThreads
in interfaceThreadPool.SizedThreadPool
- Parameters:
threads
- the minimum number of threads
-
getMaxThreads
- Specified by:
getMaxThreads
in interfaceThreadPool.SizedThreadPool
- Returns:
- the maximum number of threads
-
setMaxThreads
public void setMaxThreads(int threads) - Specified by:
setMaxThreads
in interfaceThreadPool.SizedThreadPool
- Parameters:
threads
- the maximum number of threads
-
getIdleTimeout
- Returns:
- the maximum thread idle time in ms.
- See Also:
-
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:
-
getReservedThreads
- Returns:
- number of reserved threads or -1 to indicate that the number is heuristically determined
- See Also:
-
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:
-
setThreadsPriority
public void setThreadsPriority(int priority) -
getThreadsPriority
public int getThreadsPriority() -
isDaemon
- Returns:
- whether this thread pool uses daemon threads
- See Also:
-
setDaemon
public void setDaemon(boolean daemon) - Parameters:
daemon
- whether this thread pool uses daemon threads- See Also:
-
isDetailedDump
-
setDetailedDump
public void setDetailedDump(boolean detailedDump) -
getThreads
- Specified by:
getThreads
in interfaceThreadPool
- Returns:
- The total number of threads currently in the pool
-
getIdleThreads
- Specified by:
getIdleThreads
in interfaceThreadPool
- Returns:
- The number of idle threads in the pool
-
execute
- Specified by:
execute
in interfaceExecutor
- Specified by:
execute
in interfaceTryExecutor
-
tryExecute
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.
-
isLowOnThreads
@ManagedAttribute(value="thread pool is low on threads", readonly=true) public boolean isLowOnThreads()- Specified by:
isLowOnThreads
in interfaceThreadPool
- Returns:
- True if the pool is low on threads
-
getVirtualThreadsExecutor
- Specified by:
getVirtualThreadsExecutor
in interfaceVirtualThreads.Configurable
- Returns:
- the
Executor
to use to execute tasks in virtual threads
-
setVirtualThreadsExecutor
- Specified by:
setVirtualThreadsExecutor
in interfaceVirtualThreads.Configurable
- Parameters:
executor
- theExecutor
to use to execute tasks in virtual threads- See Also:
-
doStart
Description copied from class:ContainerLifeCycle
Starts the managed lifecycle beans in the order they were added.- Overrides:
doStart
in classContainerLifeCycle
- Throws:
AbstractLifeCycle.StopException
- If thrown, the lifecycle will immediately be stopped.Exception
- If there was a problem starting. Will cause a transition to FAILED state
-
doStop
Description copied from class:ContainerLifeCycle
Stops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStop
in classContainerLifeCycle
- Throws:
Exception
- If there was a problem stopping. Will cause a transition to FAILED state
-
join
Description copied from interface:ThreadPool
Blocks until the thread pool isstopped
.- Specified by:
join
in interfaceThreadPool
- Throws:
InterruptedException
- if thread was interrupted
-
getThreadPoolBudget
- Specified by:
getThreadPoolBudget
in interfaceThreadPool.SizedThreadPool
- Returns:
- a ThreadPoolBudget for this sized thread pool, or null of no ThreadPoolBudget can be returned
-
newThread
-
dump
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
-
toString
- Overrides:
toString
in classAbstractLifeCycle
-