File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed
vpro-shared-util/src/main/java/nl/vpro/util Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 1
1
package nl .vpro .util ;
2
2
3
3
import lombok .extern .log4j .Log4j2 ;
4
- import org .junit .platform .launcher .TestExecutionListener ;
5
- import org .junit .platform .launcher .TestPlan ;
6
4
7
5
import java .util .concurrent .ForkJoinPool ;
6
+ import java .util .concurrent .TimeUnit ;
7
+
8
+ import org .junit .platform .launcher .TestExecutionListener ;
9
+ import org .junit .platform .launcher .TestPlan ;
8
10
9
11
/**
10
12
* A junit TestExecutionListener that just makes sure that all ThreadPools are shutdown after the tests.
13
+ * Also, it calls {@link ForkJoinPool#awaitQuiescence(long, TimeUnit)} (100s) on {@link ForkJoinPool#commonPool()}
11
14
*/
12
15
@ Log4j2
13
16
public class ThreadPoolShutdowner implements TestExecutionListener {
14
17
15
18
@ Override
16
19
public void testPlanExecutionFinished (TestPlan testPlan ) {
20
+
17
21
ThreadPools .shutdown ();
18
- log .info ("Shutting down ForkJoinPool.commonPool() too" );
19
- ForkJoinPool .commonPool ().shutdown ();
22
+ log .info ("Waiting for ForkJoinPool.commonPool() too" );
23
+ // commonPool cannot be shut down. But you can wait for tasks
24
+ boolean b = ForkJoinPool .commonPool ().awaitQuiescence (100 , TimeUnit .SECONDS );
25
+
20
26
}
21
27
22
28
}
Original file line number Diff line number Diff line change @@ -94,13 +94,12 @@ public Thread newThread(@NonNull Runnable r) {
94
94
false ,
95
95
Thread .NORM_PRIORITY ));
96
96
97
-
98
- public static void shutdown () {
97
+ public static void shutdown () {
99
98
log .info ("Shutting down thread pools" );
100
99
copyExecutor .shutdown ();
101
100
startUpExecutor .shutdown ();
102
101
backgroundExecutor .shutdown ();
103
102
longBackgroundExecutor .shutdown ();
104
- }
103
+ }
105
104
}
106
105
You can’t perform that action at this time.
0 commit comments