@@ -38,16 +38,22 @@ public static void saveInstance(Object obj) {
38
38
39
39
public static void submitNonCritical (Runnable runnable ) {
40
40
saveInstance (runnable );
41
- CompletableFuture .supplyAsync (() -> runnable , getInstance ().nonCriticalExecutor )
42
- .thenAccept (Runnable ::run )
43
- .handle (Processing ::exceptionHandler );
41
+ ExecutorService executor = getInstance ().nonCriticalExecutor ;
42
+ if (executor .isShutdown ()) {
43
+ return ;
44
+ }
45
+ CompletableFuture .supplyAsync (() -> {
46
+ runnable .run ();
47
+ return true ;
48
+ }, executor ).handle (Processing ::exceptionHandler );
44
49
}
45
50
46
51
public static void submitCritical (Runnable runnable ) {
47
52
saveInstance (runnable );
48
- CompletableFuture .supplyAsync (() -> runnable , getInstance ().criticalExecutor )
49
- .thenAccept (Runnable ::run )
50
- .handle (Processing ::exceptionHandler );
53
+ CompletableFuture .supplyAsync (() -> {
54
+ runnable .run ();
55
+ return true ;
56
+ }, getInstance ().criticalExecutor ).handle (Processing ::exceptionHandler );
51
57
}
52
58
53
59
public static void submitNonCritical (Runnable ... runnables ) {
@@ -72,15 +78,17 @@ public static <T> Future<T> submit(Callable<T> task) {
72
78
73
79
public static <T > Future <T > submitNonCritical (Callable <T > task ) {
74
80
saveInstance (task );
75
- return CompletableFuture .supplyAsync (() -> task , getInstance ().nonCriticalExecutor )
76
- .thenApply (tCallable -> {
77
- try {
78
- return tCallable .call ();
79
- } catch (Exception e ) {
80
- throw new IllegalStateException (e );
81
- }
82
- })
83
- .handle (Processing ::exceptionHandler );
81
+ ExecutorService executor = getInstance ().nonCriticalExecutor ;
82
+ if (executor .isShutdown ()) {
83
+ return null ;
84
+ }
85
+ return CompletableFuture .supplyAsync (() -> {
86
+ try {
87
+ return task .call ();
88
+ } catch (Exception e ) {
89
+ throw new IllegalStateException (e );
90
+ }
91
+ }, getInstance ().nonCriticalExecutor ).handle (Processing ::exceptionHandler );
84
92
}
85
93
86
94
private static <T > T exceptionHandler (T t , Throwable throwable ) {
@@ -92,15 +100,13 @@ private static <T> T exceptionHandler(T t, Throwable throwable) {
92
100
93
101
public static <T > Future <T > submitCritical (Callable <T > task ) {
94
102
saveInstance (task );
95
- return CompletableFuture .supplyAsync (() -> task , getInstance ().criticalExecutor )
96
- .thenApply (tCallable -> {
97
- try {
98
- return tCallable .call ();
99
- } catch (Exception e ) {
100
- throw new IllegalStateException (e );
101
- }
102
- })
103
- .handle (Processing ::exceptionHandler );
103
+ return CompletableFuture .supplyAsync (() -> {
104
+ try {
105
+ return task .call ();
106
+ } catch (Exception e ) {
107
+ throw new IllegalStateException (e );
108
+ }
109
+ }, getInstance ().criticalExecutor ).handle (Processing ::exceptionHandler );
104
110
}
105
111
106
112
public static Processing getInstance () {
0 commit comments