Package org.jlayer.util
Class ForkJoinUtil
java.lang.Object
org.jlayer.util.ForkJoinUtil
This class establishes the base for the parallel implementation of generated
LayerMethods
and
VectorLayer's
special methods for connecting or associating layers.
The nested class LayerAction
use the Fork/Join Framework
as presented in the Tutorial
Fork/Join.
It extends RecursiveAction
and has two constructors.
Accordingly, the overriding method compute()
has
two branches, which depend on the constructor having been chosen to create an object:
-
LayerAction(ActionItem actionItem)
==> the given actionItem is computed directly -
LayerAction(List<ActionItem> actionList)
==> the items of the given actionList are computed recursively
The nested class ActionItem
serves as a helper class to store
"compute()-objects", and the method getX1Slices()
can be used to establish lists of ActionItems.
A once generated layerAction can be executed by calling invoke():
-
ForkJoinImpl.invoke(layerAction);
- Author:
- Gerd Kock
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
(package private) static class
a tuple for representing slices -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription(package private) static ForkJoinUtil.Tuple[]
getX1Slices
(int x1Length) separates the range with lengthx1Length
into a number of slices.static <T> T
invoke
(ForkJoinTask<T> task) establishes the ForkJoinPool - iff not yet present - and invokes the given task.
-
Field Details
-
pool
-
-
Constructor Details
-
ForkJoinUtil
public ForkJoinUtil()
-
-
Method Details
-
invoke
establishes the ForkJoinPool - iff not yet present - and invokes the given task.- Type Parameters:
T
- the type of the task's result- Parameters:
task
- the task- Returns:
- the taks's result
-
getX1Slices
separates the range with lengthx1Length
into a number of slices.The number of resulting slices is given by
Example:Runtime.getRuntime().availableProcessors()
.-
"x1Length == 11"
==> given range is[0..10]
-
Runtime.getRuntime().availableProcessors() == 3
- returns
[ [0,4], [4,8], [8,11] ]
- Parameters:
x1Length
- the upper bound of the range- Returns:
- an array of
Tuples
describing the separation
-
-