@@ -38,6 +38,7 @@ public class Processing implements SubSystem {
38
38
private final ErrorLogger errorLogger ;
39
39
40
40
private ExecutorService nonCriticalExecutor ;
41
+ private ExecutorService nonCriticalSingleThreadExecutor ;
41
42
private ExecutorService criticalExecutor ;
42
43
43
44
@ Inject
@@ -50,6 +51,7 @@ public Processing(
50
51
this .logger = logger ;
51
52
this .errorLogger = errorLogger ;
52
53
nonCriticalExecutor = createExecutor (6 , "Plan Non critical-pool-%d" );
54
+ nonCriticalSingleThreadExecutor = createExecutor (1 , "Plan Non critical-pool-single-threaded-%d" );
53
55
criticalExecutor = createExecutor (2 , "Plan Critical-pool-%d" );
54
56
}
55
57
@@ -71,13 +73,18 @@ public void submit(Runnable runnable) {
71
73
}
72
74
73
75
public CompletableFuture <Boolean > submitNonCritical (Runnable runnable ) {
74
- if (runnable == null || nonCriticalExecutor .isShutdown ()) {
76
+ return submitNonCritical (runnable , false );
77
+ }
78
+
79
+ public CompletableFuture <Boolean > submitNonCritical (Runnable runnable , boolean singleThreaded ) {
80
+ ExecutorService executorService = singleThreaded ? nonCriticalSingleThreadExecutor : nonCriticalExecutor ;
81
+ if (runnable == null || executorService .isShutdown ()) {
75
82
return null ;
76
83
}
77
84
return CompletableFuture .supplyAsync (() -> {
78
85
runnable .run ();
79
86
return true ;
80
- }, nonCriticalExecutor ).handle (this ::exceptionHandlerNonCritical );
87
+ }, executorService ).handle (this ::exceptionHandlerNonCritical );
81
88
}
82
89
83
90
public CompletableFuture <Boolean > submitCritical (Runnable runnable ) {
@@ -138,21 +145,25 @@ public void enable() {
138
145
if (nonCriticalExecutor .isShutdown ()) {
139
146
nonCriticalExecutor = createExecutor (6 , "Plan Non critical-pool-%d" );
140
147
}
148
+ if (nonCriticalSingleThreadExecutor .isShutdown ()) {
149
+ nonCriticalSingleThreadExecutor = createExecutor (1 , "Plan Non critical-pool-single-threaded-%d" );
150
+ }
141
151
if (criticalExecutor .isShutdown ()) {
142
152
criticalExecutor = createExecutor (2 , "Plan Critical-pool-%d" );
143
153
}
144
154
}
145
155
146
156
@ Override
147
157
public void disable () {
148
- shutdownNonCriticalExecutor ();
158
+ shutdownNonCriticalExecutors ();
149
159
shutdownCriticalExecutor ();
150
160
ensureShutdown ();
151
161
logger .info (locale .get ().getString (PluginLang .DISABLED_PROCESSING_COMPLETE ));
152
162
}
153
163
154
- private void shutdownNonCriticalExecutor () {
164
+ private void shutdownNonCriticalExecutors () {
155
165
nonCriticalExecutor .shutdownNow ();
166
+ nonCriticalSingleThreadExecutor .shutdownNow ();
156
167
}
157
168
158
169
private void shutdownCriticalExecutor () {
@@ -184,12 +195,16 @@ private void ensureShutdown() {
184
195
if (!nonCriticalExecutor .isTerminated ()) {
185
196
nonCriticalExecutor .shutdownNow ();
186
197
}
198
+ if (!nonCriticalSingleThreadExecutor .isTerminated ()) {
199
+ nonCriticalSingleThreadExecutor .shutdownNow ();
200
+ }
187
201
if (!criticalExecutor .isTerminated () && !criticalExecutor .awaitTermination (1 , TimeUnit .SECONDS )) {
188
202
criticalExecutor .shutdownNow ();
189
203
}
190
204
} catch (InterruptedException e ) {
191
205
logger .error ("Processing shutdown thread interrupted: " + e .getMessage ());
192
206
nonCriticalExecutor .shutdownNow ();
207
+ nonCriticalSingleThreadExecutor .shutdownNow ();
193
208
criticalExecutor .shutdownNow ();
194
209
Thread .currentThread ().interrupt ();
195
210
}
0 commit comments