Skip to content

Commit

Permalink
Reuse createThreadPool for DefaultPool
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Horn <[email protected]>
  • Loading branch information
FlorentinD and knutwalker committed Oct 6, 2023
1 parent 0668c70 commit e8cb4d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e8cb4d4

Please sign in to comment.