From e8cb4d47348b99d2e47647b367c5ea7767979b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florentin=20D=C3=B6rre?= Date: Fri, 6 Oct 2023 14:48:39 +0200 Subject: [PATCH] Reuse createThreadPool for DefaultPool Co-authored-by: Paul Horn --- .../org/neo4j/gds/core/concurrency/DefaultPool.java | 13 +------------ .../gds/core/concurrency/ExecutorServiceUtil.java | 4 ++++ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/neo4j/gds/core/concurrency/DefaultPool.java b/core/src/main/java/org/neo4j/gds/core/concurrency/DefaultPool.java index 1ba55b09b2..f16efe316b 100644 --- a/core/src/main/java/org/neo4j/gds/core/concurrency/DefaultPool.java +++ b/core/src/main/java/org/neo4j/gds/core/concurrency/DefaultPool.java @@ -22,25 +22,14 @@ import org.neo4j.gds.concurrency.PoolSizes; import org.neo4j.gds.concurrency.PoolSizesService; -import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ExecutorService; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; public final class DefaultPool { public static final ExecutorService INSTANCE = createDefaultPool(PoolSizesService.poolSizes()); private static ExecutorService createDefaultPool(PoolSizes poolSizes) { - return new ThreadPoolExecutor( - poolSizes.corePoolSize(), - poolSizes.maxPoolSize(), - 30L, - TimeUnit.SECONDS, - new ArrayBlockingQueue<>(poolSizes.corePoolSize() * 50), - ExecutorServiceUtil.DEFAULT_THREAD_FACTORY, - new ExecutorServiceUtil.CallerBlocksPolicy() - ); + return ExecutorServiceUtil.createThreadPool(poolSizes.corePoolSize(), poolSizes.maxPoolSize()); } private DefaultPool() {} diff --git a/core/src/main/java/org/neo4j/gds/core/concurrency/ExecutorServiceUtil.java b/core/src/main/java/org/neo4j/gds/core/concurrency/ExecutorServiceUtil.java index b2ef74ce5c..ae6906da22 100644 --- a/core/src/main/java/org/neo4j/gds/core/concurrency/ExecutorServiceUtil.java +++ b/core/src/main/java/org/neo4j/gds/core/concurrency/ExecutorServiceUtil.java @@ -49,6 +49,10 @@ public static ExecutorService createSingleThreadPool(String threadPrefix) { return Executors.newSingleThreadExecutor(NamedThreadFactory.daemon(threadPrefix)); } + static ExecutorService createThreadPool(int corePoolSize, int maxPoolSize) { + return createThreadPool(THREAD_NAME_PREFIX, corePoolSize, maxPoolSize); + } + public static ExecutorService createThreadPool(String threadPrefix, int corePoolSize, int maxPoolSize) { return new ThreadPoolExecutor( corePoolSize,