By default, the size of commonPool inside parallelStream should be cpu_cores - 1
.
But, in my application it is always greater than the hardware cpu_cores
.
VisualVM screenshot:
so confused, I'd already searched half of the Internet but could not find the answer to this.
My config:
Runtime.getRuntime().availableProcessors()=12
java.util.concurrent.ForkJoinPool.common.parallelism=null
(default setting)
My code:
final CountDownLatch countDownLatch = new CountDownLatch(tempList.size());
tempList.parallelStream().forEach(om -> {
countDownLatch.countDown();
redisReBloomService.add(config.getRedisKey(), om.getChannelNo());
});
countDownLatch.await();
Also, I had tried custom pool setting and it does not work either-
ForkJoinPool forkJoinPool = new ForkJoinPool(3);
forkJoinPool.submit(() -> {
tempList.parallelStream().forEach(om -> {
countDownLatch.countDown();
redisReBloomService.add(config.getRedisKey(), om.getChannelNo());
}).get();
});
Some info: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html Custom thread pool in Java 8 parallel stream