Package org.eclipse.jetty.util.thread
Class VirtualThreadPool
java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.util.thread.VirtualThreadPool
- All Implemented Interfaces:
Executor,Container,Destroyable,Dumpable,Dumpable.DumpableContainer,LifeCycle,ThreadPool,TryExecutor,VirtualThreads.Configurable
@ManagedObject("A thread non-pool for virtual threads")
public class VirtualThreadPool
extends ContainerLifeCycle
implements ThreadPool, Dumpable, TryExecutor, VirtualThreads.Configurable
An implementation of ThreadPool interface that does not pool, but instead uses VirtualThreads.
It is possible to specify the max number of concurrent tasks run by virtual threads, to help limiting resource usage in applications, especially in the case of load spikes. An unlimited number of tasks run concurrently by virtual threads may compete for resources and eventually bring the system down due to memory exhaustion.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer, Dumpable.DumpAppendableNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.ThreadPool
ThreadPool.SizedThreadPoolNested 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, STOPPINGFields inherited from interface org.eclipse.jetty.util.thread.TryExecutor
NO_TRY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.voidintintintDeprecated, for removal: This API element is subject to removal in a future version.getName()intbooleanbooleanbooleanGet if this pool is tracking virtual threads.voidjoin()Blocks until the thread pool isstopped.voidsetDetailedDump(boolean detailedDump) voidsetMaxConcurrentTasks(int maxConcurrentTasks) voidsetMaxThreads(int maxTasks) Deprecated, for removal: This API element is subject to removal in a future version.usesetMaxConcurrentTasks(int)insteadvoidSets the name of this thread pool, used as a prefix for the thread names.voidsetTracking(boolean tracking) voidsetVirtualThreadsExecutor(Executor executor) booleantryExecute(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, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListenersMethods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpableMethods inherited from interface org.eclipse.jetty.util.VirtualThreads.Configurable
isUseVirtualThreads, setUseVirtualThreads
-
Constructor Details
-
VirtualThreadPool
public VirtualThreadPool() -
VirtualThreadPool
public VirtualThreadPool(int maxTasks)
-
-
Method Details
-
getName
- Returns:
- the name of this thread pool
-
setName
Sets the name of this thread pool, used as a prefix for the thread names.
- Parameters:
name- the name of this thread pool
-
getMaxThreads
Deprecated, for removal: This API element is subject to removal in a future version.usegetMaxConcurrentTasks()instead- Returns:
- the maximum number of concurrent tasks run by virtual threads
-
setMaxThreads
Deprecated, for removal: This API element is subject to removal in a future version.usesetMaxConcurrentTasks(int)instead- Parameters:
maxTasks- the maximum number of concurrent tasks run by virtual threads
-
getMaxConcurrentTasks
@ManagedAttribute("The max number of concurrent tasks run by virtual threads") public int getMaxConcurrentTasks()- Returns:
- the maximum number of concurrent tasks run by virtual threads
-
setMaxConcurrentTasks
public void setMaxConcurrentTasks(int maxConcurrentTasks) - Parameters:
maxConcurrentTasks- the maximum number of concurrent tasks run by virtual threads
-
isTracking
Get if this pool is tracking virtual threads.- Returns:
trueif the virtual threads will be tracked.- See Also:
-
setTracking
public void setTracking(boolean tracking) -
isDetailedDump
@ManagedAttribute("Whether to report additional details in the dump") public boolean isDetailedDump() -
setDetailedDump
public void setDetailedDump(boolean detailedDump) -
doStart
Description 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.Exception- If there was a problem starting. Will cause a transition to FAILED state
-
doStop
Description copied from class:ContainerLifeCycleStops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStopin classContainerLifeCycle- Throws:
Exception- If there was a problem stopping. Will cause a transition to FAILED state
-
getVirtualThreadsExecutor
- Specified by:
getVirtualThreadsExecutorin interfaceVirtualThreads.Configurable- Returns:
- the
Executorto use to execute tasks in virtual threads
-
setVirtualThreadsExecutor
- Specified by:
setVirtualThreadsExecutorin interfaceVirtualThreads.Configurable- Parameters:
executor- theExecutorto use to execute tasks in virtual threads- See Also:
-
join
Description copied from interface:ThreadPoolBlocks until the thread pool isstopped.- Specified by:
joinin interfaceThreadPool- Throws:
InterruptedException- if thread was interrupted
-
getThreads
public int getThreads()- Specified by:
getThreadsin interfaceThreadPool- Returns:
- The total number of threads currently in the pool
-
getIdleThreads
public int getIdleThreads()- Specified by:
getIdleThreadsin interfaceThreadPool- Returns:
- The number of idle threads in the pool
-
isLowOnThreads
public boolean isLowOnThreads()- Specified by:
isLowOnThreadsin interfaceThreadPool- Returns:
- True if the pool is low on threads
-
tryExecute
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.
-
execute
- Specified by:
executein interfaceExecutor- Specified by:
executein interfaceTryExecutor
-
getMaxConcurrentTasks()instead