public interface SafeIterator<E> extends Iterator<E>
In comparison to the regular iterator, the safe iterator guarantees correct results even as events are being processed by other threads. The cost is that the iterator holds one or more locks that must be released via the close method. Any locks are acquired at the time an instance is created.
NOTE: An application MUST explicitly close the safe iterator instance using the close method, to release locks held by the iterator. The call to the close method should be done in a finally block to make sure the iterator gets closed.
Multiple safe iterators may be not be used at the same time by different application threads. A single application thread may hold and use multiple safe iterators however this is discouraged.
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the safe itertor, releasing locks.
|
forEachRemaining, hasNext, next, remove