@@ -29,6 +29,7 @@ public class ExecutorServiceManager {
29
29
private ExecutorService workflowExecutor ;
30
30
private ExecutorService cachingExecutorService ;
31
31
private boolean started ;
32
+ private ConfigurationService configurationService ;
32
33
33
34
ExecutorServiceManager (ConfigurationService configurationService ) {
34
35
start (configurationService );
@@ -95,30 +96,38 @@ public ExecutorService reconcileExecutorService() {
95
96
}
96
97
97
98
public ExecutorService workflowExecutorService () {
99
+ lazyInitWorkflowExecutorService ();
98
100
return workflowExecutor ;
99
101
}
100
102
103
+ private synchronized void lazyInitWorkflowExecutorService () {
104
+ if (workflowExecutor == null ) {
105
+ workflowExecutor =
106
+ new InstrumentedExecutorService (configurationService .getWorkflowExecutorService ());
107
+ }
108
+ }
109
+
101
110
public ExecutorService cachingExecutorService () {
102
111
return cachingExecutorService ;
103
112
}
104
113
105
114
public void start (ConfigurationService configurationService ) {
106
115
if (!started ) {
116
+ this .configurationService = configurationService ; // used to lazy init workflow executor
107
117
this .cachingExecutorService = Executors .newCachedThreadPool ();
108
118
this .executor = new InstrumentedExecutorService (configurationService .getExecutorService ());
109
- this .workflowExecutor =
110
- new InstrumentedExecutorService (configurationService .getWorkflowExecutorService ());
111
119
started = true ;
112
120
}
113
121
}
114
122
115
123
public void stop (Duration gracefulShutdownTimeout ) {
116
124
try {
117
- var parallelExec = Executors .newFixedThreadPool (3 );
118
125
log .debug ("Closing executor" );
126
+ var parallelExec = Executors .newFixedThreadPool (3 );
119
127
parallelExec .invokeAll (List .of (shutdown (executor , gracefulShutdownTimeout ),
120
128
shutdown (workflowExecutor , gracefulShutdownTimeout ),
121
129
shutdown (cachingExecutorService , gracefulShutdownTimeout )));
130
+ workflowExecutor = null ;
122
131
parallelExec .shutdownNow ();
123
132
started = false ;
124
133
} catch (InterruptedException e ) {
@@ -130,6 +139,10 @@ public void stop(Duration gracefulShutdownTimeout) {
130
139
private static Callable <Void > shutdown (ExecutorService executorService ,
131
140
Duration gracefulShutdownTimeout ) {
132
141
return () -> {
142
+ // workflow executor can be null
143
+ if (executorService == null ) {
144
+ return null ;
145
+ }
133
146
executorService .shutdown ();
134
147
if (!executorService .awaitTermination (gracefulShutdownTimeout .toMillis (),
135
148
TimeUnit .MILLISECONDS )) {
0 commit comments