Package org.apfloat.internal
Class ParallelRunnable
java.lang.Object
org.apfloat.internal.ParallelRunnable
- All Implemented Interfaces:
Runnable
Abstract class for a
Runnable
that can be run in parallel by
multiple threads. Internally, the ParallelRunnable
splits the
work to many small batches, which are run one at a time, and can be run in
parallel by multiple threads. The ParallelRunnable
isn't
completed until all batches are completed, i.e. the run()
method
only returns when all batches are completed.- Since:
- 1.1
- Version:
- 1.14.0
- Author:
- Mikko Tommila
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected long
Get the preferred batch size.protected Runnable
getRunnable
(int startValue, int length) Get the Runnable object for strides which fit in anint
.protected Runnable
getRunnable
(long startValue, long length) Get the Runnable object for strides which fit only in along
.boolean
Returns if there is some work that may be currently processed but not yet finished.boolean
Returns if there is still enough work left to start a new batch.final void
run()
Repeatedly get a batch of work and run it, until all batches are completed.final boolean
runBatch()
Run one batch if available.
-
Constructor Details
-
ParallelRunnable
protected ParallelRunnable(long length) Subclass constructor.- Parameters:
length
- The length of the work to be run.
-
-
Method Details
-
run
-
runBatch
public final boolean runBatch()Run one batch if available. Returnstrue
if a batch was actually acquired and run,false
if all batches were already started and none could be run. This method can be used by any thread to steal and complete a minimal amount of work.Note that if a batch could not be run, it does not mean that all of the batches are already completed - some could still be running.
- Returns:
- If a batch was actually run.
-
isWorkToBeStarted
public boolean isWorkToBeStarted()Returns if there is still enough work left to start a new batch.- Returns:
- If a new batch could be started to still perform some work.
- Since:
- 1.9.0
-
isWorkToBeCompleted
public boolean isWorkToBeCompleted()Returns if there is some work that may be currently processed but not yet finished.- Returns:
- If there is still some work left that is not completed yet.
- Since:
- 1.9.0
-
getRunnable
Get the Runnable object for strides which fit in anint
.- Parameters:
startValue
- The starting value for the stride.length
- The length of the stride.- Returns:
- The Runnable object for the specified stride.
-
getRunnable
Get the Runnable object for strides which fit only in along
.- Parameters:
startValue
- The starting value for the stride.length
- The length of the stride.- Returns:
- The Runnable object for the specified stride.
-
getPreferredBatchSize
protected long getPreferredBatchSize()Get the preferred batch size.- Returns:
- The preferred batch size.
- Since:
- 1.7.0
-