24 |
|
* is <em>NOT</em> a constant-time operation. Because of the |
25 |
|
* asynchronous nature of these queues, determining the current number |
26 |
|
* of elements requires an O(n) traversal. |
27 |
+ |
* @since 1.5 |
28 |
+ |
* @author Doug Lea |
29 |
|
* |
30 |
|
**/ |
31 |
|
public class LinkedQueue<E> extends AbstractQueue<E> |
43 |
|
|
44 |
|
// Atomics support |
45 |
|
|
46 |
< |
private final static AtomicReferenceFieldUpdater<LinkedQueue, AtomicLinkedNode> tailUpdater = new AtomicReferenceFieldUpdater<LinkedQueue, AtomicLinkedNode>(new LinkedQueue[0], new AtomicLinkedNode[0], "tail"); |
47 |
< |
private final static AtomicReferenceFieldUpdater<LinkedQueue, AtomicLinkedNode> headUpdater = new AtomicReferenceFieldUpdater<LinkedQueue, AtomicLinkedNode>(new LinkedQueue[0], new AtomicLinkedNode[0], "head"); |
46 |
> |
private static final AtomicReferenceFieldUpdater<LinkedQueue, AtomicLinkedNode> tailUpdater = new AtomicReferenceFieldUpdater<LinkedQueue, AtomicLinkedNode>(new LinkedQueue[0], new AtomicLinkedNode[0], "tail"); |
47 |
> |
private static final AtomicReferenceFieldUpdater<LinkedQueue, AtomicLinkedNode> headUpdater = new AtomicReferenceFieldUpdater<LinkedQueue, AtomicLinkedNode>(new LinkedQueue[0], new AtomicLinkedNode[0], "head"); |
48 |
|
|
49 |
|
private boolean casTail(AtomicLinkedNode cmp, AtomicLinkedNode val) { |
50 |
|
return tailUpdater.compareAndSet(this, cmp, val); |
83 |
|
} |
84 |
|
|
85 |
|
public boolean offer(E x) { |
86 |
< |
if (x == null) throw new IllegalArgumentException(); |
86 |
> |
if (x == null) throw new NullPointerException(); |
87 |
|
AtomicLinkedNode n = new AtomicLinkedNode(x, null); |
88 |
|
for(;;) { |
89 |
|
AtomicLinkedNode t = tail; |
335 |
|
* |
336 |
|
* @serialData All of the elements (each an <tt>E</tt>) in |
337 |
|
* the proper order, followed by a null |
338 |
+ |
* @param s the stream |
339 |
|
*/ |
340 |
|
private void writeObject(java.io.ObjectOutputStream s) |
341 |
|
throws java.io.IOException { |
357 |
|
/** |
358 |
|
* Reconstitute the Queue instance from a stream (that is, |
359 |
|
* deserialize it). |
360 |
+ |
* @param s the stream |
361 |
|
*/ |
362 |
|
private void readObject(java.io.ObjectInputStream s) |
363 |
|
throws java.io.IOException, ClassNotFoundException { |