Java Reference
In-Depth Information
7.2.1. Working with RecursiveTask
To submit tasks to this pool, you have to create a subclass of RecursiveTask<R>, where R is the
type of the result produced by the parallelized task (and each of its subtasks) or of
RecursiveAction if the task returns no result (it could be updating other nonlocal structures,
though). To define RecursiveTasks you need only implement its single abstract method,
compute:
protected abstract R compute();
This method defines both the logic of splitting the task at hand into subtasks and the algorithm
to produce the result of a single subtask when it's no longer possible or convenient to further
divide it. For this reason an implementation of this method often resembles the following
pseudocode:
if (task is small enough or no longer divisible) {
compute task sequentially
} else {
split task in two subtasks
call this method recursively possibly further splitting each subtask
wait for the completion of all subtasks
combine the results of each subtask
}
In general there are no precise criteria for deciding whether a given task should be further
divided or not, but there are various heuristics that you can follow to help you with this decision.
We clarify them in more detail in section 7.2.1 . The recursive task-splitting process is visually
synthesized by figure 7.3 .
 
Search WWH ::




Custom Search