ThreadPoolExecutor vs ForkJoinPool: stealing subtasks

后端 未结 2 1388
感动是毒
感动是毒 2021-02-20 17:41

From java docs,

A ForkJoinPool differs from other kinds of ExecutorService mainly by virtue of employing work-stealing: all threads in the pool attempt to fi

2条回答
  •  一个人的身影
    2021-02-20 18:30

    If you have 3000 tasks in advance, and they are not going to spawn other tasks, the two will not behave substantially differently: with 10 threads, 10 tasks will be run at a time until they are all done.

    ForkJoinPool is designed for the case where you have one or a few tasks to start with, but the tasks know how to split themselves up into subtasks. In this situation, ForkJoinPool is optimized to permit tasks to check on the availability of processing threads and split themselves up appropriately.

提交回复
热议问题