Class ForkJoinUtil

java.lang.Object
org.jlayer.util.ForkJoinUtil

public class ForkJoinUtil extends Object
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:
  • Field Details

  • Constructor Details

    • ForkJoinUtil

      public ForkJoinUtil()
  • Method Details

    • invoke

      public static <T> T invoke(ForkJoinTask<T> task)
      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

      static ForkJoinUtil.Tuple[] getX1Slices(int x1Length)
      separates the range with length x1Length into a number of slices.

      The number of resulting slices is given by Runtime.getRuntime().availableProcessors().

      Example:
      • "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