public abstract class ParallelRunnable extends Object implements Runnable
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.Modifier | Constructor and Description |
---|---|
protected |
ParallelRunnable(long length)
Subclass constructor.
|
Modifier and Type | Method and Description |
---|---|
protected long |
getPreferredBatchSize()
Get the preferred batch size.
|
protected Runnable |
getRunnable(int startValue,
int length)
Get the Runnable object for strides which fit in an
int . |
protected Runnable |
getRunnable(long startValue,
long length)
Get the Runnable object for strides which fit only in a
long . |
void |
run()
Repeatedly get a batch of work and run it, until all batches are
completed.
|
boolean |
runBatch()
Run one batch if available.
|
protected ParallelRunnable(long length)
length
- The length of the work to be run.public final void run()
public final boolean runBatch()
true
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.
protected Runnable getRunnable(int startValue, int length)
int
.startValue
- The starting value for the stride.length
- The length of the stride.protected Runnable getRunnable(long startValue, long length)
long
.startValue
- The starting value for the stride.length
- The length of the stride.protected long getPreferredBatchSize()
Copyright © 2019. All rights reserved.