Class VirtualThreads

java.lang.Object
org.eclipse.jetty.util.VirtualThreads

public class VirtualThreads extends Object

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

See Also:
  • Method Details

    • areSupported

      public static boolean areSupported()
      Returns:
      whether the runtime supports virtual threads
    • executeOnVirtualThread

      @Deprecated(forRemoval=true) public static void executeOnVirtualThread(Runnable task)
      Deprecated, for removal: This API element is subject to removal in a future version.

      Starts 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
    • getDefaultVirtualThreadsExecutor

      public static Executor getDefaultVirtualThreadsExecutor()
      Returns:
      a default virtual thread per task Executor
    • getVirtualThreadsExecutor

      public static Executor getVirtualThreadsExecutor(Executor executor)
      Parameters:
      executor - the Executor to obtain a virtual threads Executor from
      Returns:
      a virtual threads Executor obtained from the given Executor
    • isUseVirtualThreads

      public static boolean isUseVirtualThreads(Executor executor)

      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