@@ -18,9 +18,8 @@ public class ExecutorServiceManager {
18
18
private static ExecutorServiceManager instance ;
19
19
private final ExecutorService executor ;
20
20
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 ());
24
23
private final int terminationTimeoutSeconds ;
25
24
26
25
private ExecutorServiceManager (ExecutorService executor , ExecutorService workflowExecutor ,
@@ -73,13 +72,13 @@ public ExecutorService workflowExecutorService() {
73
72
}
74
73
75
74
public static void executeInParallel (Runnable callable ) {
76
- executeInParallel (() -> {
75
+ instance (). executeInParallel (() -> {
77
76
callable .run ();
78
77
return null ;
79
78
});
80
79
}
81
80
82
- public static <T > T executeInParallel (Callable <T > callable ) {
81
+ public <T > T executeInParallel (Callable <T > callable ) {
83
82
try {
84
83
return threadPool .submit (callable ).get ();
85
84
} catch (InterruptedException | ExecutionException e ) {
@@ -90,6 +89,7 @@ public static <T> T executeInParallel(Callable<T> callable) {
90
89
private void doStop () {
91
90
try {
92
91
log .debug ("Closing executor" );
92
+ threadPool .shutdown ();
93
93
executor .shutdown ();
94
94
workflowExecutor .shutdown ();
95
95
if (!workflowExecutor .awaitTermination (terminationTimeoutSeconds , TimeUnit .SECONDS )) {
@@ -98,8 +98,6 @@ private void doStop() {
98
98
if (!executor .awaitTermination (terminationTimeoutSeconds , TimeUnit .SECONDS )) {
99
99
executor .shutdownNow (); // if we timed out, waiting, cancel everything
100
100
}
101
-
102
- threadPool .shutdown ();
103
101
} catch (InterruptedException e ) {
104
102
log .debug ("Exception closing executor: {}" , e .getLocalizedMessage ());
105
103
}
0 commit comments