org.omnaest.utils.structure.iterator
Class ThreadLocalCachedIterator<E>
java.lang.Object
org.omnaest.utils.structure.iterator.ThreadLocalCachedIterator<E>
- Type Parameters:
E -
- All Implemented Interfaces:
- Iterator<E>
public class ThreadLocalCachedIterator<E>
- extends Object
- implements Iterator<E>
Iterator decorator which uses a ThreadLocal to store any element within an internal ThreadLocal
instance. This means that when calling the hasNext() method the next() method of the decorated and internal
available Iterator is called and the result Object is stored within the ThreadLocal.
Based on this behavior any client have to ensure that the same Thread is calling the next() function, if it
has called the hasNext() beforehand. Otherwise elements returned from the original Iterator can get lost.
The big advantage of this implementation is the ability of high multithreaded performance and reliability of the
Iterator contract.
The underlying Iterator instance will only be locked between the immediately following hasNext() and
next() function calls.
- Author:
- Omnaest
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ThreadLocalCachedIterator
public ThreadLocalCachedIterator(Iterator<E> iterator)
- Parameters:
iterator - - See Also:
ThreadLocalCachedIterator
hasNext
public boolean hasNext()
- Specified by:
hasNext in interface Iterator<E>
next
public E next()
- Specified by:
next in interface Iterator<E>
remove
public void remove()
- Specified by:
remove in interface Iterator<E>
Copyright © 2013. All Rights Reserved.