Skip to content

Commit eedd830

Browse files
committed
fix: make common thread pool attached to instance instead of static
1 parent b7e5817 commit eedd830

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ExecutorServiceManager.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ public class ExecutorServiceManager {
1818
private static ExecutorServiceManager instance;
1919
private final ExecutorService executor;
2020
private final ExecutorService workflowExecutor;
21-
22-
private static final ForkJoinPool threadPool = new ForkJoinPool(
23-
Runtime.getRuntime().availableProcessors());
21+
private final ForkJoinPool threadPool =
22+
new ForkJoinPool(Runtime.getRuntime().availableProcessors());
2423
private final int terminationTimeoutSeconds;
2524

2625
private ExecutorServiceManager(ExecutorService executor, ExecutorService workflowExecutor,
@@ -73,13 +72,13 @@ public ExecutorService workflowExecutorService() {
7372
}
7473

7574
public static void executeInParallel(Runnable callable) {
76-
executeInParallel(() -> {
75+
instance().executeInParallel(() -> {
7776
callable.run();
7877
return null;
7978
});
8079
}
8180

82-
public static <T> T executeInParallel(Callable<T> callable) {
81+
public <T> T executeInParallel(Callable<T> callable) {
8382
try {
8483
return threadPool.submit(callable).get();
8584
} catch (InterruptedException | ExecutionException e) {
@@ -90,6 +89,7 @@ public static <T> T executeInParallel(Callable<T> callable) {
9089
private void doStop() {
9190
try {
9291
log.debug("Closing executor");
92+
threadPool.shutdown();
9393
executor.shutdown();
9494
workflowExecutor.shutdown();
9595
if (!workflowExecutor.awaitTermination(terminationTimeoutSeconds, TimeUnit.SECONDS)) {
@@ -98,8 +98,6 @@ private void doStop() {
9898
if (!executor.awaitTermination(terminationTimeoutSeconds, TimeUnit.SECONDS)) {
9999
executor.shutdownNow(); // if we timed out, waiting, cancel everything
100100
}
101-
102-
threadPool.shutdown();
103101
} catch (InterruptedException e) {
104102
log.debug("Exception closing executor: {}", e.getLocalizedMessage());
105103
}

0 commit comments

Comments
 (0)