src/share/classes/java/util/concurrent/LinkedBlockingDeque.java

Print this page




 987         lock.lock();
 988         try {
 989             for (Node<E> f = first; f != null; ) {
 990                 f.item = null;
 991                 Node<E> n = f.next;
 992                 f.prev = null;
 993                 f.next = null;
 994                 f = n;
 995             }
 996             first = last = null;
 997             count = 0;
 998             notFull.signalAll();
 999         } finally {
1000             lock.unlock();
1001         }
1002     }
1003 
1004     /**
1005      * Returns an iterator over the elements in this deque in proper sequence.
1006      * The elements will be returned in order from first (head) to last (tail).
1007      * The returned {@code Iterator} is a "weakly consistent" iterator that

1008      * will never throw {@link java.util.ConcurrentModificationException
1009      * ConcurrentModificationException},
1010      * and guarantees to traverse elements as they existed upon
1011      * construction of the iterator, and may (but is not guaranteed to)
1012      * reflect any modifications subsequent to construction.
1013      *
1014      * @return an iterator over the elements in this deque in proper sequence
1015      */
1016     public Iterator<E> iterator() {
1017         return new Itr();
1018     }
1019 
1020     /**
1021      * Returns an iterator over the elements in this deque in reverse
1022      * sequential order.  The elements will be returned in order from
1023      * last (tail) to first (head).
1024      * The returned {@code Iterator} is a "weakly consistent" iterator that

1025      * will never throw {@link java.util.ConcurrentModificationException
1026      * ConcurrentModificationException},
1027      * and guarantees to traverse elements as they existed upon
1028      * construction of the iterator, and may (but is not guaranteed to)
1029      * reflect any modifications subsequent to construction.


1030      */
1031     public Iterator<E> descendingIterator() {
1032         return new DescendingItr();
1033     }
1034 
1035     /**
1036      * Base class for Iterators for LinkedBlockingDeque
1037      */
1038     private abstract class AbstractItr implements Iterator<E> {
1039         /**
1040          * The next node to return in next()
1041          */
1042          Node<E> next;
1043 
1044         /**
1045          * nextItem holds on to item fields because once we claim that
1046          * an element exists in hasNext(), we must return item read
1047          * under lock (in advance()) even if it was in the process of
1048          * being removed when hasNext() was called.
1049          */




 987         lock.lock();
 988         try {
 989             for (Node<E> f = first; f != null; ) {
 990                 f.item = null;
 991                 Node<E> n = f.next;
 992                 f.prev = null;
 993                 f.next = null;
 994                 f = n;
 995             }
 996             first = last = null;
 997             count = 0;
 998             notFull.signalAll();
 999         } finally {
1000             lock.unlock();
1001         }
1002     }
1003 
1004     /**
1005      * Returns an iterator over the elements in this deque in proper sequence.
1006      * The elements will be returned in order from first (head) to last (tail).
1007      *
1008      * <p>The returned iterator is a "weakly consistent" iterator that
1009      * will never throw {@link java.util.ConcurrentModificationException
1010      * ConcurrentModificationException}, and guarantees to traverse
1011      * elements as they existed upon construction of the iterator, and
1012      * may (but is not guaranteed to) reflect any modifications
1013      * subsequent to construction.
1014      *
1015      * @return an iterator over the elements in this deque in proper sequence
1016      */
1017     public Iterator<E> iterator() {
1018         return new Itr();
1019     }
1020 
1021     /**
1022      * Returns an iterator over the elements in this deque in reverse
1023      * sequential order.  The elements will be returned in order from
1024      * last (tail) to first (head).
1025      *
1026      * <p>The returned iterator is a "weakly consistent" iterator that
1027      * will never throw {@link java.util.ConcurrentModificationException
1028      * ConcurrentModificationException}, and guarantees to traverse
1029      * elements as they existed upon construction of the iterator, and
1030      * may (but is not guaranteed to) reflect any modifications
1031      * subsequent to construction.
1032      *
1033      * @return an iterator over the elements in this deque in reverse order
1034      */
1035     public Iterator<E> descendingIterator() {
1036         return new DescendingItr();
1037     }
1038 
1039     /**
1040      * Base class for Iterators for LinkedBlockingDeque
1041      */
1042     private abstract class AbstractItr implements Iterator<E> {
1043         /**
1044          * The next node to return in next()
1045          */
1046          Node<E> next;
1047 
1048         /**
1049          * nextItem holds on to item fields because once we claim that
1050          * an element exists in hasNext(), we must return item read
1051          * under lock (in advance()) even if it was in the process of
1052          * being removed when hasNext() was called.
1053          */