1 year ago

#183331

test-img

Dave

How parallel stream works in Java after increasing ForkJoinPool?

I see that the default ForkJoinPool.commonPool size is one less thread than number of CPU cores. And also to make custom pool we can either use follows,

1. java.util.concurrent.ForkJoinPool.common.parallelism=30
2. ForkJoinPool fjp = new ForkJoinPool(30);

But I am struggling to understand how this actually works. Multithreading is an OS thing. So if a processor has 2 cores and 4 threads (details that OperatingSystem shows), and I changed the Java parallelism to 30 how will it work with the CPU? What is the maximum number of threads it will create instantly and can run simultaneously? Will it create 30 threads at the same time and process in parallel or since the CPU has 4 threads will it create 4 threads and once it is finished again another 4 threads like that? Or even how much we increase parallelism and even in Spring Boot's batch with higher grid size, will it always depend on the CPU cores and CPU's threads? Thanks in advance.

java

multithreading

parallel-processing

parallelstream

0 Answers

Your Answer

Accepted video resources