Java parallel streams run in the common fork-join pool by default, using threads equal to the number of virtual CPU cores. You can limit this via the JVM property `java.util.concurrent.forkjoinpool.common.parallelism`. A lesser-known pattern allows running a parallel stream in a custom fork-join pool: wrap the stream computation in a Callable and submit it to your own ForkJoinPool instance. Since the stream runs in a thread belonging to that pool, it uses that pool instead of the common one. The post cautions against overusing this pattern, as creating many fork-join pools can degrade performance, and recommends measuring rather than guessing performance gains.

2m watch time

Sort: