Package dev.aherscu.qa.testing.extra
Class ParallelLoop
- java.lang.Object
-
- dev.aherscu.qa.testing.extra.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 Summary
Fields Modifier and Type Field Description static ParallelLoop
PROTOTYPE
The default parallel loop; chain with threadPool and repetitions to configure.
-
Constructor Summary
Constructors Constructor Description ParallelLoop()
Constructs a default parallel loop with one thread and one repetition.ParallelLoop(AbstractExecutorService threadPool, int repetitions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
run(Function<Integer,Integer> function)
Runs specified function in configured loop.void
run(IntConsumer consumer)
Runs specified consumer in configured loop.ParallelLoop
withRepetitions(int repetitions)
ParallelLoop
withThreadPool(AbstractExecutorService threadPool)
-
-
-
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.
-
ParallelLoop
public ParallelLoop(AbstractExecutorService threadPool, int repetitions)
-
-
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).
-
-