Class ParallelLoop


  • public final class ParallelLoop
    extends Object
    Parallel looping with specified threads, repetitions and block of code.

    NOTE: there is a library class at https://github.com/pablormier/parallel-loops

    • Field Detail

      • PROTOTYPE

        public static final ParallelLoop PROTOTYPE
        The default parallel loop; chain with threadPool and repetitions to configure.
        See Also:
        ParallelLoop()
    • Constructor Detail

      • ParallelLoop

        public ParallelLoop()
        Constructs a default parallel loop with one thread and one repetition.
    • Method Detail

      • run

        public void run​(Function<Integer,​Integer> function)
        Runs specified function in configured loop.
        Parameters:
        function - the function to run; is called with the run identifier and expected to return it
        Throws:
        CancellationException - if the computation was cancelled
      • run

        public void run​(IntConsumer consumer)
        Runs specified consumer in configured loop.
        Parameters:
        consumer - the consumer to run; is called with the run identifier.
      • withThreadPool

        public ParallelLoop withThreadPool​(AbstractExecutorService threadPool)
        Returns:
        a clone of this object, except with this updated property (returns this if an identical value is passed).
      • withRepetitions

        public ParallelLoop withRepetitions​(int repetitions)
        Returns:
        a clone of this object, except with this updated property (returns this if an identical value is passed).