diff --git a/src/org/jgroups/util/ThreadPool.java b/src/org/jgroups/util/ThreadPool.java index 8f768dd1e5..01d97d7b18 100644 --- a/src/org/jgroups/util/ThreadPool.java +++ b/src/org/jgroups/util/ThreadPool.java @@ -25,7 +25,7 @@ * @since 5.2 */ public class ThreadPool implements Lifecycle { - private static final MethodHandle EXECUTORS_NEW_THREAD_PER_TASK_EXECUTOR=getNewThreadPerTaskExecutorHandle(); + private static final MethodHandle EXECUTORS_NEW_VIRTUAL_THREAD_FACTORY=getNewVirtualThreadFactoryHandle(); protected Executor thread_pool; protected Log log; protected ThreadFactory thread_factory; @@ -261,7 +261,7 @@ protected static ExecutorService createThreadPool(int min_threads, int max_threa String rejection_policy, BlockingQueue queue, final ThreadFactory factory, Log log) { - if(!factory.useVirtualThreads() || EXECUTORS_NEW_THREAD_PER_TASK_EXECUTOR == null) { + if(!factory.useVirtualThreads() || EXECUTORS_NEW_VIRTUAL_THREAD_FACTORY == null) { ThreadPoolExecutor pool=new ThreadPoolExecutor(min_threads, max_threads, keep_alive_time, TimeUnit.MILLISECONDS, queue, factory); RejectedExecutionHandler handler=Util.parseRejectionPolicy(rejection_policy); @@ -272,18 +272,19 @@ protected static ExecutorService createThreadPool(int min_threads, int max_threa } try { - return (ExecutorService)EXECUTORS_NEW_THREAD_PER_TASK_EXECUTOR.invokeExact((java.util.concurrent.ThreadFactory)factory); + return (ExecutorService)EXECUTORS_NEW_VIRTUAL_THREAD_FACTORY.invokeExact(); } catch(Throwable t) { throw new IllegalStateException(String.format("failed to create virtual thread pool: %s", t)); } } - protected static MethodHandle getNewThreadPerTaskExecutorHandle() { - MethodType type=MethodType.methodType(ExecutorService.class, java.util.concurrent.ThreadFactory.class); + protected static MethodHandle getNewVirtualThreadFactoryHandle() { + MethodType type=MethodType.methodType(ExecutorService.class); String[] names={ - "newThreadPerTaskExecutor", // jdk 17+ - "newUnboundedExecutor" // jdk 15 & 16 + "newVirtualThreadPerTaskExecutor", // jdk 18-21 + "newVirtualThreadExecutor", // jdk 17 + "newUnboundedVirtualThreadExecutor" // jdk 15 & 16 }; MethodHandles.Lookup LOOKUP=MethodHandles.publicLookup();