ThreadPoolExecutor vs ForkJoinPool: stealing subtasks

From java docs,

A ForkJoinPool differs from other types of ExecutorService mainly due to the use of job theft: all threads in the pool try to find and execute subtasks created by other active tasks (ultimately blocking the wait for work if they do not exist).

This allows efficient processing when most tasks generate other subtasks (like most ForkJoinTasks). When setting asyncMode to true in constructors, ForkJoinPools may also be suitable for use with event-style tasks that never connect.

After going through the ForkJoinPool example , unlike ThreadPoolExecutor, I did not see the parameter for setting the queue size. I did not understand how the mechanism of the theft of ForkJoinPool.

//creating the ThreadPoolExecutor

ThreadPoolExecutor executorPool = new ThreadPoolExecutor(2, 10, 60, TimeUnit.SECONDS, 
new ArrayBlockingQueue<Runnable>(3000), threadFactory, rejectionHandler);

Suppose I created a ThreadPoolExecutor with 10 threads and 3000 Callable tasks. How do these threads share the sub-task execution load?

And how does the ForkJoin pool behave differently for the same use case?

+4
source share
2 answers

ForkJoinPool - , , (.. ). ForkJoinTask ( , ).

, . , / , . , invoker .

" " . "", . , " " .

. , " " / . .

, . , N . , " " , !

+4

3000 , , -: 10 10 , .

ForkJoinPool , , , . ForkJoinPool , .

+4

Source: https://habr.com/ru/post/1613932/


All Articles