Package eu.cloudnetservice.driver.util
Class ExecutorServiceUtil
java.lang.Object
eu.cloudnetservice.driver.util.ExecutorServiceUtil
A utility class to easier access methods around executor services.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final dev.derklaro.reflexion.MethodAccessor<Method>private static final dev.derklaro.reflexion.MethodAccessor<Method>private static final dev.derklaro.reflexion.MethodAccessor<Method>private static final dev.derklaro.reflexion.MethodAccessor<Method>private static final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull ExecutorServicenewVirtualThreadExecutor(@NonNull String threadNamePrefix, @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).static booleanGet if virtual threads are available and will be returned bynewVirtualThreadExecutor(String, Function)(in other word if this jvm is running on java 19 or newer and has preview features enabled).
-
Field Details
-
VIRTUAL_THREADS_AVAILABLE
private static final boolean VIRTUAL_THREADS_AVAILABLE -
VIRTUAL_BUILDER_GETTER
-
VIRTUAL_BUILDER_NAME
-
VIRTUAL_BUILDER_TO_FACTORY
-
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 bynewVirtualThreadExecutor(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.
-