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 11package nl .vpro .util ;
22
33import lombok .extern .log4j .Log4j2 ;
4- import org .junit .platform .launcher .TestExecutionListener ;
5- import org .junit .platform .launcher .TestPlan ;
64
75import 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 ;
810
911/**
1012 * 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()}
1114 */
1215@ Log4j2
1316public class ThreadPoolShutdowner implements TestExecutionListener {
1417
1518 @ Override
1619 public void testPlanExecutionFinished (TestPlan testPlan ) {
20+
1721 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+
2026 }
2127
2228}
Original file line number Diff line number Diff line change @@ -94,13 +94,12 @@ public Thread newThread(@NonNull Runnable r) {
9494 false ,
9595 Thread .NORM_PRIORITY ));
9696
97-
98- public static void shutdown () {
97+ public static void shutdown () {
9998 log .info ("Shutting down thread pools" );
10099 copyExecutor .shutdown ();
101100 startUpExecutor .shutdown ();
102101 backgroundExecutor .shutdown ();
103102 longBackgroundExecutor .shutdown ();
104- }
103+ }
105104}
106105
You can’t perform that action at this time.
0 commit comments