Class ExecutorServiceUtil

java.lang.Object
eu.cloudnetservice.driver.util.ExecutorServiceUtil

@Internal public final class ExecutorServiceUtil extends Object
A utility class to easier access methods around executor services.
Since:
4.0
  • Field Details

    • VIRTUAL_THREADS_AVAILABLE

      private static final boolean VIRTUAL_THREADS_AVAILABLE
    • VIRTUAL_BUILDER_GETTER

      private static final dev.derklaro.reflexion.MethodAccessor<Method> VIRTUAL_BUILDER_GETTER
    • VIRTUAL_BUILDER_NAME

      private static final dev.derklaro.reflexion.MethodAccessor<Method> VIRTUAL_BUILDER_NAME
    • VIRTUAL_BUILDER_TO_FACTORY

      private static final dev.derklaro.reflexion.MethodAccessor<Method> VIRTUAL_BUILDER_TO_FACTORY
    • EXECUTORS_NEW_THREAD_PER_TASK

      private static final dev.derklaro.reflexion.MethodAccessor<Method> EXECUTORS_NEW_THREAD_PER_TASK
  • Constructor Details

    • ExecutorServiceUtil

      private ExecutorServiceUtil()
  • Method Details

    • virtualThreadsAvailable

      public static boolean virtualThreadsAvailable()
      Get if virtual threads are available and will be returned by newVirtualThreadExecutor(String, Function) (in other word if this jvm is running on java 19 or newer and has preview features enabled).
      Returns:
      true if virtual threads are available, false otherwise.
    • newVirtualThreadExecutor

      @NonNull public static @NonNull ExecutorService newVirtualThreadExecutor(@NonNull @NonNull String threadNamePrefix, @NonNull @NonNull Function<ThreadFactory,ExecutorService> fallbackExecutorFactory)
      Creates a new virtual thread executor if the current jvm supports them (running on Java 19+ with preview features enabled). If virtual threads are not supported a new thread factory based on the given name format will be built and passed to the given fallback executor factory.
      Parameters:
      threadNamePrefix - the prefix of the thread name, not including %d (for the thread id).
      fallbackExecutorFactory - the fallback executor service factory if virtual threads are not supported.
      Returns:
      a new virtual thread based executor if possible, or a factory supplied by the fallback supplier.
      Throws:
      NullPointerException - if the given name prefix or fallback executor factory is null.