Search code examples
javaforkjoinpoolwork-stealing

Whats the benefit to use wrokstealing from ForkJoin rather than just ordinary thread pool's queue?


Whats the benefit to use workstealing from ForkJoin rather than just ordinary thread pool's queue? is the "workstealing" from ForkJoinPool better then just take tasks from the thread pool's queue? Isn't it stealing?


Solution

  • ForkJoinPool is designed for Recursive Actions. This might for example be a divide-and-conquer algorithm like MergeSort. In such an algorithm, one Thread would usually wait for the children to finish.

    This is where "workstealing" comes in. The work would be stolen from the waiting Thread by the ones that actually have work to do.

    If you have a fixed amount of Threads that will not spawn new Threads, you should just use a normal ExecutorService ThreadPool.