Skip to content

Commit 21935fb

Browse files
committed
Common pool cannot be shut down.
1 parent 182ea3d commit 21935fb

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
package nl.vpro.util;
22

33
import lombok.extern.log4j.Log4j2;
4-
import org.junit.platform.launcher.TestExecutionListener;
5-
import org.junit.platform.launcher.TestPlan;
64

75
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;
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
1316
public 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
}

vpro-shared-util/src/main/java/nl/vpro/util/ThreadPools.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)