@@ -29,6 +29,7 @@ public class ExecutorServiceManager {
2929 private ExecutorService workflowExecutor ;
3030 private ExecutorService cachingExecutorService ;
3131 private boolean started ;
32+ private ConfigurationService configurationService ;
3233
3334 ExecutorServiceManager (ConfigurationService configurationService ) {
3435 start (configurationService );
@@ -95,30 +96,38 @@ public ExecutorService reconcileExecutorService() {
9596 }
9697
9798 public ExecutorService workflowExecutorService () {
99+ lazyInitWorkflowExecutorService ();
98100 return workflowExecutor ;
99101 }
100102
103+ private synchronized void lazyInitWorkflowExecutorService () {
104+ if (workflowExecutor == null ) {
105+ workflowExecutor =
106+ new InstrumentedExecutorService (configurationService .getWorkflowExecutorService ());
107+ }
108+ }
109+
101110 public ExecutorService cachingExecutorService () {
102111 return cachingExecutorService ;
103112 }
104113
105114 public void start (ConfigurationService configurationService ) {
106115 if (!started ) {
116+ this .configurationService = configurationService ; // used to lazy init workflow executor
107117 this .cachingExecutorService = Executors .newCachedThreadPool ();
108118 this .executor = new InstrumentedExecutorService (configurationService .getExecutorService ());
109- this .workflowExecutor =
110- new InstrumentedExecutorService (configurationService .getWorkflowExecutorService ());
111119 started = true ;
112120 }
113121 }
114122
115123 public void stop (Duration gracefulShutdownTimeout ) {
116124 try {
117- var parallelExec = Executors .newFixedThreadPool (3 );
118125 log .debug ("Closing executor" );
126+ var parallelExec = Executors .newFixedThreadPool (3 );
119127 parallelExec .invokeAll (List .of (shutdown (executor , gracefulShutdownTimeout ),
120128 shutdown (workflowExecutor , gracefulShutdownTimeout ),
121129 shutdown (cachingExecutorService , gracefulShutdownTimeout )));
130+ workflowExecutor = null ;
122131 parallelExec .shutdownNow ();
123132 started = false ;
124133 } catch (InterruptedException e ) {
@@ -130,6 +139,10 @@ public void stop(Duration gracefulShutdownTimeout) {
130139 private static Callable <Void > shutdown (ExecutorService executorService ,
131140 Duration gracefulShutdownTimeout ) {
132141 return () -> {
142+ // workflow executor can be null
143+ if (executorService == null ) {
144+ return null ;
145+ }
133146 executorService .shutdown ();
134147 if (!executorService .awaitTermination (gracefulShutdownTimeout .toMillis (),
135148 TimeUnit .MILLISECONDS )) {
0 commit comments