diff --git a/tooling/src/main/java/org/opencds/cqf/tooling/common/ThreadUtils.java b/tooling/src/main/java/org/opencds/cqf/tooling/common/ThreadUtils.java index 72f78e7d1..56a07190b 100644 --- a/tooling/src/main/java/org/opencds/cqf/tooling/common/ThreadUtils.java +++ b/tooling/src/main/java/org/opencds/cqf/tooling/common/ThreadUtils.java @@ -16,6 +16,8 @@ public class ThreadUtils { private static List runningExecutors = new ArrayList<>(); + private static final int threadPoolCount = Integer.getInteger("threadutils.pool.count", Runtime.getRuntime().availableProcessors()); + /** * Executes a list of tasks concurrently using a thread pool. *

@@ -62,11 +64,15 @@ public static void executeTasks(List> tasks, ExecutorService exec } public static void executeTasks(List> tasks) { - executeTasks(tasks, Executors.newCachedThreadPool()); + ExecutorService executor = Executors.newFixedThreadPool(threadPoolCount); + + executeTasks(tasks, executor); } public static void executeTasks(Queue> callables) { - executeTasks(new ArrayList<>(callables), Executors.newCachedThreadPool()); + ExecutorService executor = Executors.newFixedThreadPool(threadPoolCount); + + executeTasks(new ArrayList<>(callables), executor); } public static void shutdownRunningExecutors() { @@ -77,7 +83,7 @@ public static void shutdownRunningExecutors() { } runningExecutors = new ArrayList<>(); }catch (Exception e){ - //fail silently, shutting down anyways + //fail silently, shutting down anyway } } }