I read a great article about the fork-join framework in Java 7, and the idea is that, with ForkJoinPool
and ForkJoinTask
, the threads in the pool can get the sub tasks from other tasks, so it's able to use less threads to handle more tasks.
Then I tried to use a normal ExecutorService
to do the same work, and found I can't tell the difference, since when I submit a new task to the pool, the task will be run on another available thread.
The only difference I can tell is if I use ForkJoinPool
, I don't need to pass the pool to the tasks, because I can call task.fork()
to make it running on another thread. But with normal ExecutorService
, I have to pass the pool to the task, or make it a static, so inside the task, I can call pool.submit(newTask)
Do I miss something?
(You can view the living code from https://github.com/freewind/fork-join-test/tree/master/src)