Package org.eclipse.jetty.util
Class VirtualThreads
java.lang.Object
org.eclipse.jetty.util.VirtualThreads
Utility class to use to query the runtime for virtual thread support, and, if virtual threads are supported, to start virtual threads.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Implementations of this interface can be configured to use virtual threads. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
static void
Deprecated, for removal: This API element is subject to removal in a future version.static Executor
Get a default virtual thread per taskExecutor
.static Executor
getNamedVirtualThreadsExecutor
(String namePrefix) Get a virtual threadsExecutor
that names the virtual threads according to the provided name prefix.static Executor
getVirtualThreadsExecutor
(Executor executor) static boolean
isUseVirtualThreads
(Executor executor) Tests whether the given executor implementsVirtualThreads.Configurable
and it has been configured to use virtual threads.static boolean
-
Method Details
-
areSupported
public static boolean areSupported()- Returns:
- whether the runtime supports virtual threads
-
executeOnVirtualThread
Deprecated, for removal: This API element is subject to removal in a future version.usegetVirtualThreadsExecutor(Executor)
insteadStarts a virtual thread to execute the given task, or throws
UnsupportedOperationException
if virtual threads are not supported.- Parameters:
task
- the task to execute in a virtual thread- See Also:
-
isVirtualThread
public static boolean isVirtualThread()- Returns:
- whether the current thread is a virtual thread
-
getNamedVirtualThreadsExecutor
Get a virtual threadsExecutor
that names the virtual threads according to the provided name prefix. While named virtual threads enable observability they do also incur a minor performance penalty.- Parameters:
namePrefix
- the prefix to use for the name of the virtual threads- Returns:
- a virtual threads
Executor
that will name the virtual threads according to the provided name prefix.
-
getDefaultVirtualThreadsExecutor
Get a default virtual thread per taskExecutor
.- Returns:
- a default virtual thread per task
Executor
-
getVirtualThreadsExecutor
- Parameters:
executor
- theExecutor
to obtain a virtual threadsExecutor
from- Returns:
- a virtual threads
Executor
obtained from the givenExecutor
-
isUseVirtualThreads
Tests whether the given executor implements
VirtualThreads.Configurable
and it has been configured to use virtual threads.- Parameters:
executor
- the Executor to test- Returns:
- whether the given executor implements
VirtualThreads.Configurable
and it has been configured to use virtual threads
-
getVirtualThreadsExecutor(Executor)
instead