Top Description Inners Fields Constructors Methods
org.eclipse.jetty.util

public Class VirtualThreads

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, java.util.concurrent.Executor, .Executors, org.slf4j.Logger, .LoggerFactory

Utility class to use to query the runtime for virtual thread support, and, if virtual threads are supported, to start virtual threads.

See Also
areSupported(), getVirtualThreadsExecutor(Executor), isVirtualThread()

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
VirtualThreads.Configurable

Implementations of this interface can be configured to use virtual threads.

Field Summary

Modifier and TypeField and Description
private static final Executor
private static final Method
private static final Logger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean
areSupported()

Returns: whether the runtime supports virtual threads

public static void
executeOnVirtualThread(Runnable
the task to execute in a virtual thread
task
)
Deprecated for removal. use getVirtualThreadsExecutor(Executor) instead

Starts a virtual thread to execute the given task, or throws UnsupportedOperationException if virtual threads are not supported.

public static Executor

Returns:

a default virtual thread per task Executor
getDefaultVirtualThreadsExecutor
()

Get a default virtual thread per task Executor.

private static Method
public static Executor
getVirtualThreadsExecutor(Executor
the Executor to obtain a virtual threads Executor from
executor
)

Returns: a virtual threads Executor obtained from the given Executor

public static boolean

Returns:

whether the given executor implements Configurable and it has been configured to use virtual threads
isUseVirtualThreads
(Executor
the Executor to test
executor
)

Tests whether the given executor implements Configurable and it has been configured to use virtual threads.

public static boolean
isVirtualThread()

Returns: whether the current thread is a virtual thread

private static Method
private static Executor
private static void
warn()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

executorback to summary
private static final Executor executor
isVirtualThreadback to summary
private static final Method isVirtualThread
LOGback to summary
private static final Logger LOG

Constructor Detail

VirtualThreadsback to summary
private VirtualThreads()

Method Detail

areSupportedback to summary
public static boolean areSupported()
Returns:boolean

whether the runtime supports virtual threads

executeOnVirtualThreadback to summary
public static void executeOnVirtualThread(Runnable task)

Deprecated

for removal.

use getVirtualThreadsExecutor(Executor) instead

Starts a virtual thread to execute the given task, or throws UnsupportedOperationException if virtual threads are not supported.

Parameters
task:Runnable

the task to execute in a virtual thread

Annotations
@Deprecated
forRemoval:true
See Also
areSupported()
getDefaultVirtualThreadsExecutorback to summary
public static Executor getDefaultVirtualThreadsExecutor()

Get a default virtual thread per task Executor.

Returns:Executor

a default virtual thread per task Executor

getIsVirtualThreadMethodback to summary
private static Method getIsVirtualThreadMethod()
getVirtualThreadsExecutorback to summary
public static Executor getVirtualThreadsExecutor(Executor executor)
Parameters
executor:Executor

the Executor to obtain a virtual threads Executor from

Returns:Executor

a virtual threads Executor obtained from the given Executor

isUseVirtualThreadsback to summary
public static boolean isUseVirtualThreads(Executor executor)

Tests whether the given executor implements Configurable and it has been configured to use virtual threads.

Parameters
executor:Executor

the Executor to test

Returns:boolean

whether the given executor implements Configurable and it has been configured to use virtual threads

isVirtualThreadback to summary
public static boolean isVirtualThread()
Returns:boolean

whether the current thread is a virtual thread

probeIsVirtualThreadback to summary
private static Method probeIsVirtualThread()
probeVirtualThreadExecutorback to summary
private static Executor probeVirtualThreadExecutor()
warnback to summary
private static void warn()
org.eclipse.jetty.util back to summary

public Interface VirtualThreads.Configurable

Known Direct Implementers
org.eclipse.jetty.util.thread.ExecutorThreadPool, org.eclipse.jetty.util.thread.QueuedThreadPool

Implementations of this interface can be configured to use virtual threads.

Whether virtual threads are actually used depends on whether the runtime supports virtual threads and, if the runtime supports them, whether they are configured to be used via setVirtualThreadsExecutor(Executor).

Method Summary

Modifier and TypeMethod and Description
public default Executor
getVirtualThreadsExecutor()

Returns: the Executor to use to execute tasks in virtual threads

public default boolean
isUseVirtualThreads()
Deprecated for removal. use getVirtualThreadsExecutor() instead

Returns: whether to use virtual threads

public default void
setUseVirtualThreads(boolean
whether to use virtual threads
useVirtualThreads
)
Deprecated for removal. use setVirtualThreadsExecutor(Executor) instead

public default void
setVirtualThreadsExecutor(Executor
the Executor to use to execute tasks in virtual threads
executor
)

Method Detail

getVirtualThreadsExecutorback to summary
public default Executor getVirtualThreadsExecutor()
Returns:Executor

the Executor to use to execute tasks in virtual threads

isUseVirtualThreadsback to summary
public default boolean isUseVirtualThreads()

Deprecated

for removal.

use getVirtualThreadsExecutor() instead

Returns:boolean

whether to use virtual threads

Annotations
@Deprecated
forRemoval:true
setUseVirtualThreadsback to summary
public default void setUseVirtualThreads(boolean useVirtualThreads)

Deprecated

for removal.

use setVirtualThreadsExecutor(Executor) instead

Parameters
useVirtualThreads:boolean

whether to use virtual threads

Annotations
@Deprecated
forRemoval:true
Exceptions
UnsupportedOperationException:
if the runtime does not support virtual threads
See Also
areSupported()
setVirtualThreadsExecutorback to summary
public default void setVirtualThreadsExecutor(Executor executor)
Parameters
executor:Executor

the Executor to use to execute tasks in virtual threads

Exceptions
UnsupportedOperationException:
if the runtime does not support virtual threads
See Also
areSupported()