Java Reference
In-Depth Information
Optimizing Parallel Processing with Fork/Join
Problem
You want to optimize use of multiple processors and/or large problem spaces.
Solution
Use the Fork/Join framework.
Discussion
Fork/Join is an
ExecutorService
intended mainly for reasonably large tasks that can natur-
ally be divided recursively, where you don't have to ensure equal timing for each division. It
uses work-stealing to keep threads busy.
The basic means of using Fork/Join is to extend
RecursiveTask
or
RecursiveAction
and
override its
compute()
method along these lines:
iif
(
assigned portion of work is
“
small enough
”
) {
perform the work myself
}
else
else
{
split my work into two pieces
invoke the two pieces and await the results
}