Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class ThreadUtils {

private static List<ExecutorService> 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.
* <p>
Expand Down Expand Up @@ -62,11 +64,15 @@ public static void executeTasks(List<Callable<Void>> tasks, ExecutorService exec
}

public static void executeTasks(List<Callable<Void>> tasks) {
executeTasks(tasks, Executors.newCachedThreadPool());
ExecutorService executor = Executors.newFixedThreadPool(threadPoolCount);

executeTasks(tasks, executor);
}

public static void executeTasks(Queue<Callable<Void>> callables) {
executeTasks(new ArrayList<>(callables), Executors.newCachedThreadPool());
ExecutorService executor = Executors.newFixedThreadPool(threadPoolCount);

executeTasks(new ArrayList<>(callables), executor);
}

public static void shutdownRunningExecutors() {
Expand All @@ -77,7 +83,7 @@ public static void shutdownRunningExecutors() {
}
runningExecutors = new ArrayList<>();
}catch (Exception e){
//fail silently, shutting down anyways
//fail silently, shutting down anyway
}
}
}
Loading