Java Reference
In-Depth Information
Fork
Subproblem
Join
Subproblem
Problem
Solution
Subproblem
Subproblem
F IGURE 30.27
The nonoverlapping subproblems are solved in parallel.
The framework defines a task using the ForkJoinTask class, as shown in Figure 30.28
and executes a task in an instance of ForkJoinPool , as shown in Figure 30.29.
ForkJoinTask
ForkJoinPool
«interface»
java.util.concurrent.Future<V>
+cancel(interrupt: boolean): boolean
+get(): V
Attempts to cancel this task.
Waits if needed for the computation to complete and
returns the result.
Returns true if this task is completed.
+isDone(): boolean
java.util.concurrent.ForkJoinTask<V>
+adapt(Runnable task): ForkJoinTask<V>
+fork(): ForkJoinTask<V>
+join(): V
+invoke(): V
ForkJoinTask
Returns a
from a runnable task.
Arranges asynchronous execution of the task.
Returns the result of computations when it is done.
Performs the task and awaits for its completion, and returns its
result.
Forks the given tasks and returns when all tasks are completed.
+invokeAll(tasks ForkJoinTask<?>…): void
java.util.concurrent.RecursiveAction<V>
#compute(): void
Defines how task is performed.
java.util.concurrent.RecursiveTask<V>
#compute(): V
Defines how task is performed. Return the
value after the task is completed.
F IGURE 30.28
The ForkJoinTask class defines a task for asynchronous execution.
«interface»
java.util.concurrent.ExecutorService
See Figure 30.7
java.util.concurrent.ForkJoinPool
+ForkJoinPool()
+ForkJoinPool(parallelism: int)
+invoke(ForkJoinTask<T>): T
ForkJoinPool
Creates a
with all available processors.
ForkJoinPool
Creates a
with the specified number of processors.
Performs the task and returns its result upon completion.
F IGURE 30.29
The ForkJoinPool executes Fork/Join tasks.
 
 
Search WWH ::




Custom Search