T - public class LinkedListLock<T>
extends java.util.LinkedList<T>
LinkedList with the capability of a lock() to detect and prevent ConcurrentModificationException-
Problem is, that a ConcurrentModificationException is thrown only on the iterator, and not on the causing add(Object).
Yet it is not finished but ready to use for add(Object), because all other operations to add need to be overridden too.
add(Object) is overridden, throws an exception if lock()
because this would cause later a ConcurrentModificationException detected by the Iterator.
AbstractSequentialList.iterator() (also in 'for(elemem:list)') call lock()
unlock()
<_ul>>| Modifier and Type | Field and Description |
|---|---|
(package private) boolean |
bLock
If true then add should throw an exception because an iterator is active.
|
private static long |
serialVersionUID |
| Constructor and Description |
|---|
LinkedListLock() |
LinkedListLock(java.util.Collection<? extends T> c) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(T d)
Overridden form of
LinkedList.add(Object) throws with IllegalstateException if called under lock() |
java.util.Iterator<T> |
iterator()
Overridden operator locks, can set here a breakpoint to see whether lock was nnot set before, also to insert the correct
unlock() |
boolean |
lock()
Locks the list to use it with an #iterator()
|
void |
unlock()
This is necessary after finish the iteration because else,
add(Object) is not possible. |
add, addAll, addAll, addFirst, addLast, clear, clone, contains, descendingIterator, element, get, getFirst, getLast, indexOf, lastIndexOf, listIterator, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, remove, remove, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrence, set, size, spliterator, toArray, toArrayequals, hashCode, listIterator, removeRange, subListcontainsAll, isEmpty, removeAll, retainAll, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitprivate static final long serialVersionUID
boolean bLock
public LinkedListLock()
public LinkedListLock(java.util.Collection<? extends T> c)
public boolean lock()
public void unlock()
add(Object) is not possible.public boolean add(T d)
LinkedList.add(Object) throws with IllegalstateException if called under lock()