Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java
          +++ new/src/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java
↓ open down ↓ 57 lines elided ↑ open up ↑
  58   58   *
  59   59   * <p>This implementation employs an efficient &quot;wait-free&quot;
  60   60   * algorithm based on one described in <a
  61   61   * href="http://www.cs.rochester.edu/u/michael/PODC96.html"> Simple,
  62   62   * Fast, and Practical Non-Blocking and Blocking Concurrent Queue
  63   63   * Algorithms</a> by Maged M. Michael and Michael L. Scott.
  64   64   *
  65   65   * <p>Iterators are <i>weakly consistent</i>, returning elements
  66   66   * reflecting the state of the queue at some point at or since the
  67   67   * creation of the iterator.  They do <em>not</em> throw {@link
  68      - * ConcurrentModificationException}, and may proceed concurrently with
  69      - * other operations.  Elements contained in the queue since the creation
       68 + * java.util.ConcurrentModificationException}, and may proceed concurrently
       69 + * with other operations.  Elements contained in the queue since the creation
  70   70   * of the iterator will be returned exactly once.
  71   71   *
  72   72   * <p>Beware that, unlike in most collections, the {@code size} method
  73   73   * is <em>NOT</em> a constant-time operation. Because of the
  74   74   * asynchronous nature of these queues, determining the current number
  75   75   * of elements requires a traversal of the elements.
  76   76   *
  77   77   * <p>This class and its iterator implement all of the <em>optional</em>
  78   78   * methods of the {@link Queue} and {@link Iterator} interfaces.
  79   79   *
↓ open down ↓ 182 lines elided ↑ open up ↑
 262  262          if (h == null)
 263  263              h = t = new Node<E>(null);
 264  264          head = h;
 265  265          tail = t;
 266  266      }
 267  267  
 268  268      // Have to override just to update the javadoc
 269  269  
 270  270      /**
 271  271       * Inserts the specified element at the tail of this queue.
      272 +     * As the queue is unbounded, this method will never throw
      273 +     * {@link IllegalStateException} or return {@code false}.
 272  274       *
 273  275       * @return {@code true} (as specified by {@link Collection#add})
 274  276       * @throws NullPointerException if the specified element is null
 275  277       */
 276  278      public boolean add(E e) {
 277  279          return offer(e);
 278  280      }
 279  281  
 280  282      /**
 281  283       * Try to CAS head to p. If successful, repoint old head to itself
↓ open down ↓ 9 lines elided ↑ open up ↑
 291  293       * linked to self, which will only be true if traversing with a
 292  294       * stale pointer that is now off the list.
 293  295       */
 294  296      final Node<E> succ(Node<E> p) {
 295  297          Node<E> next = p.next;
 296  298          return (p == next) ? head : next;
 297  299      }
 298  300  
 299  301      /**
 300  302       * Inserts the specified element at the tail of this queue.
      303 +     * As the queue is unbounded, this method will never return {@code false}.
 301  304       *
 302  305       * @return {@code true} (as specified by {@link Queue#offer})
 303  306       * @throws NullPointerException if the specified element is null
 304  307       */
 305  308      public boolean offer(E e) {
 306  309          checkNotNull(e);
 307  310          final Node<E> newNode = new Node<E>(e);
 308  311  
 309  312          for (Node<E> t = tail, p = t;;) {
 310  313              Node<E> q = p.next;
↓ open down ↓ 316 lines elided ↑ open up ↑
 627  630              if (item != null)
 628  631                  al.add(item);
 629  632          }
 630  633          return al.toArray(a);
 631  634      }
 632  635  
 633  636      /**
 634  637       * Returns an iterator over the elements in this queue in proper sequence.
 635  638       * The elements will be returned in order from first (head) to last (tail).
 636  639       *
 637      -     * <p>The returned {@code Iterator} is a "weakly consistent" iterator that
      640 +     * <p>The returned iterator is a "weakly consistent" iterator that
 638  641       * will never throw {@link java.util.ConcurrentModificationException
 639      -     * ConcurrentModificationException},
 640      -     * and guarantees to traverse elements as they existed upon
 641      -     * construction of the iterator, and may (but is not guaranteed to)
 642      -     * reflect any modifications subsequent to construction.
      642 +     * ConcurrentModificationException}, and guarantees to traverse
      643 +     * elements as they existed upon construction of the iterator, and
      644 +     * may (but is not guaranteed to) reflect any modifications
      645 +     * subsequent to construction.
 643  646       *
 644  647       * @return an iterator over the elements in this queue in proper sequence
 645  648       */
 646  649      public Iterator<E> iterator() {
 647  650          return new Itr();
 648  651      }
 649  652  
 650  653      private class Itr implements Iterator<E> {
 651  654          /**
 652  655           * Next node to return item for.
↓ open down ↓ 165 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX