Skip to content

Commit 61d22e4

Browse files
committed
Fix MpmcEventBenchmark thread thrashing
1 parent 430fd92 commit 61d22e4

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

‎zthread-benchmark/src/main/java/io/github/namanoncode/zthread/benchmark/throughput/MpmcEventBenchmark.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,17 @@ public void teardownInvocation() {
111111
}
112112

113113
protected void runProducers(Runnable producerTask) throws InterruptedException {
114-
java.util.concurrent.ExecutorService executor = java.util.concurrent.Executors.newFixedThreadPool(PRODUCERS);
115-
for (int i = 0; i < PRODUCERS; i++) {
116-
executor.submit(producerTask);
114+
CountDownLatch producersDone = new CountDownLatch(PRODUCERS);
115+
for (int p = 0; p < PRODUCERS; p++) {
116+
producerPool.submit(() -> {
117+
try {
118+
producerTask.run();
119+
} finally {
120+
producersDone.countDown();
121+
}
122+
});
117123
}
118-
executor.shutdown();
119-
executor.awaitTermination(1, java.util.concurrent.TimeUnit.MINUTES);
124+
producersDone.await();
120125
}
121126

122127
private void startBlockingQueueConsumers(BlockingQueue<Object> queue, Blackhole bh) {

0 commit comments

Comments
 (0)