public class DynamicParIterator<E> extends ParIteratorAbstract<E>
ParIterator.Schedule| Modifier and Type | Field and Description |
|---|---|
protected TLocal<java.util.Iterator<E>> |
localIterator |
chunkSize, collection, data, exceptions, flags, ignoreBarrier, latch, numOfThreads, reclaimedElements, threadIDDEFAULT_CHUNKSIZE| Constructor and Description |
|---|
DynamicParIterator(java.util.Collection<E> collection,
int chunkSize,
int numOfThreads,
boolean ignoreBarrier) |
| Modifier and Type | Method and Description |
|---|---|
void |
forEachRemaining(java.util.function.Consumer<? super E> action) |
boolean |
hasNext()
Checks to see if any elements remain for the current thread.
|
boolean |
localBreak()
Attempts to excuse the current thread from continuing to iterate (and re-distribute all unprocessed elements to
the other threads).
|
E |
next()
Returns an element for the current thread to process.
|
protected java.util.Iterator<java.util.List<E>> |
partition(java.util.Collection<E> collection,
int chunkSize,
int numOfThreads) |
void |
reset()
Reset ParIterator for reuse.
|
allOtherThreadsHaveLocalBreaked, getAllExceptions, getID, globalBreak, register, register, removepublic DynamicParIterator(java.util.Collection<E> collection, int chunkSize, int numOfThreads, boolean ignoreBarrier)
protected java.util.Iterator<java.util.List<E>> partition(java.util.Collection<E> collection, int chunkSize, int numOfThreads)
public boolean hasNext()
ParIteratortrue is returned
and the current thread must follow up with a binding call to next(). A thread must continue to obtain elements
in this fashion until this method returns false.
Note that this method involves an implicit barrier for the last call to hasNext() in order to ensure all threads
finish at the same time.
true if at least one element has been reserved for the calling thread (in which case it must follow up
with a call to next()).
false otherwise (in such a case, the calling thread blocks until all the other threads have completed
their iterations).ParIterator.next()public E next()
ParIteratorhasNext() (and received true).
Note that calls to hasNext() (that return true) only allow for one corresponding and binding call to
hasNext(). Therefore, multiple calls to hasNext() have no effect until the corresponding
call to next() takes place.
ParIterator.hasNext()public boolean localBreak()
ParIterator
Therefore, (as opposed to globalBreak()) this method guarantees that even if all threads attempt to
localBreak(), at least one will fail and is left to traverse the remaining elements. Note that in many
cases, calling localBreak() will break the original scheduling policy.
true if the attempt is successful, false otherwise.ParIterator.globalBreak()public void reset()
ParIteratorreset in interface ParIterator<E>reset in class ParIteratorAbstract<E>public void forEachRemaining(java.util.function.Consumer<? super E> action)