2

I have a parallel stream like this:

mylist.stream().parallel().map(transform::docPDFTypeToItem)
.map(fdUtil::createEdiLine).forEach(document::add)

this is working on my two CPUs

now I'm trying to oversize the forkjoinpool because I have a lot of IO as described here:

new ForkJoinPool(20).submit(() -> 
    mylist.stream().parallel().map(transform::docPDFTypeToItem)
    .map(fdUtil::createEdiLine).parallel().forEach(document::add)).get())

but this is not working well, as I have only 5 threads used:

08:54:48.423 [ForkJoinPool-1-worker-18] 
08:54:48.426 [ForkJoinPool-1-worker-25] 
08:54:48.427 [ForkJoinPool-1-worker-29] 
08:54:48.430 [ForkJoinPool-1-worker-15] 
08:54:48.431 [ForkJoinPool-1-worker-11] 
08:54:50.426 [ForkJoinPool-1-worker-25] 
08:54:50.427 [ForkJoinPool-1-worker-29]
08:54:48.423 [ForkJoinPool-1-worker-18] 
08:54:48.426 [ForkJoinPool-1-worker-25] 
08:54:48.427 [ForkJoinPool-1-worker-29] 
08:54:48.430 [ForkJoinPool-1-worker-15] 
08:54:48.431 [ForkJoinPool-1-worker-11] 
08:54:50.426 [ForkJoinPool-1-worker-25] 
08:54:50.427 [ForkJoinPool-1-worker-29]
...

If I use

 System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "20");

it is working as expected (20 threads reused).

Do you know what's wrong? Does this .submit() sound like a hack?

I know I could use completableFuture like here but I think it is less readable.

Stefan Zobel
  • 3,182
  • 7
  • 28
  • 38
bodtx
  • 590
  • 9
  • 29

0 Answers0