Methods Summary |
---|
public void | clear()Does nothing.
A SynchronousQueue has no internal capacity.
|
public boolean | contains(java.lang.Object o)Always returns false.
A SynchronousQueue has no internal capacity.
return false;
|
public boolean | containsAll(java.util.Collection c)Returns false unless given collection is empty.
A SynchronousQueue has no internal capacity.
return c.isEmpty();
|
public int | drainTo(java.util.Collection c)
if (c == null)
throw new NullPointerException();
if (c == this)
throw new IllegalArgumentException();
int n = 0;
E e;
while ( (e = poll()) != null) {
c.add(e);
++n;
}
return n;
|
public int | drainTo(java.util.Collection c, int maxElements)
if (c == null)
throw new NullPointerException();
if (c == this)
throw new IllegalArgumentException();
int n = 0;
E e;
while (n < maxElements && (e = poll()) != null) {
c.add(e);
++n;
}
return n;
|
public boolean | isEmpty()Always returns true.
A SynchronousQueue has no internal capacity.
return true;
|
public java.util.Iterator | iterator()Returns an empty iterator in which hasNext always returns
false.
return new EmptyIterator<E>();
|
public boolean | offer(E o, long timeout, java.util.concurrent.TimeUnit unit)Inserts the specified element into this queue, waiting if necessary
up to the specified wait time for another thread to receive it.
if (o == null) throw new NullPointerException();
long nanos = unit.toNanos(timeout);
final ReentrantLock qlock = this.qlock;
for (;;) {
Node node;
boolean mustWait;
if (Thread.interrupted()) throw new InterruptedException();
qlock.lock();
try {
node = waitingConsumers.deq();
if ( (mustWait = (node == null)) )
node = waitingProducers.enq(o);
} finally {
qlock.unlock();
}
if (mustWait)
return node.waitForTake(nanos);
else if (node.setItem(o))
return true;
// else consumer cancelled, so retry
}
|
public boolean | offer(E o)Inserts the specified element into this queue, if another thread is
waiting to receive it.
if (o == null) throw new NullPointerException();
final ReentrantLock qlock = this.qlock;
for (;;) {
Node node;
qlock.lock();
try {
node = waitingConsumers.deq();
} finally {
qlock.unlock();
}
if (node == null)
return false;
else if (node.setItem(o))
return true;
// else retry
}
|
public E | peek()Always returns null.
A SynchronousQueue does not return elements
unless actively waited on.
return null;
|
public E | poll(long timeout, java.util.concurrent.TimeUnit unit)Retrieves and removes the head of this queue, waiting
if necessary up to the specified wait time, for another thread
to insert it.
long nanos = unit.toNanos(timeout);
final ReentrantLock qlock = this.qlock;
for (;;) {
Node node;
boolean mustWait;
if (Thread.interrupted()) throw new InterruptedException();
qlock.lock();
try {
node = waitingProducers.deq();
if ( (mustWait = (node == null)) )
node = waitingConsumers.enq(null);
} finally {
qlock.unlock();
}
if (mustWait) {
Object x = node.waitForPut(nanos);
return (E)x;
}
else {
Object x = node.getItem();
if (x != null)
return (E)x;
// else cancelled, so retry
}
}
|
public E | poll()Retrieves and removes the head of this queue, if another thread
is currently making an element available.
final ReentrantLock qlock = this.qlock;
for (;;) {
Node node;
qlock.lock();
try {
node = waitingProducers.deq();
} finally {
qlock.unlock();
}
if (node == null)
return null;
else {
Object x = node.getItem();
if (x != null)
return (E)x;
// else retry
}
}
|
public void | put(E o)Adds the specified element to this queue, waiting if necessary for
another thread to receive it.
if (o == null) throw new NullPointerException();
final ReentrantLock qlock = this.qlock;
for (;;) {
Node node;
boolean mustWait;
if (Thread.interrupted()) throw new InterruptedException();
qlock.lock();
try {
node = waitingConsumers.deq();
if ( (mustWait = (node == null)) )
node = waitingProducers.enq(o);
} finally {
qlock.unlock();
}
if (mustWait) {
node.waitForTake();
return;
}
else if (node.setItem(o))
return;
// else consumer cancelled, so retry
}
|
public int | remainingCapacity()Always returns zero.
A SynchronousQueue has no internal capacity.
return 0;
|
public boolean | remove(java.lang.Object o)Always returns false.
A SynchronousQueue has no internal capacity.
return false;
|
public boolean | removeAll(java.util.Collection c)Always returns false.
A SynchronousQueue has no internal capacity.
return false;
|
public boolean | retainAll(java.util.Collection c)Always returns false.
A SynchronousQueue has no internal capacity.
return false;
|
public int | size()Always returns zero.
A SynchronousQueue has no internal capacity.
return 0;
|
public E | take()Retrieves and removes the head of this queue, waiting if necessary
for another thread to insert it.
final ReentrantLock qlock = this.qlock;
for (;;) {
Node node;
boolean mustWait;
if (Thread.interrupted()) throw new InterruptedException();
qlock.lock();
try {
node = waitingProducers.deq();
if ( (mustWait = (node == null)) )
node = waitingConsumers.enq(null);
} finally {
qlock.unlock();
}
if (mustWait) {
Object x = node.waitForPut();
return (E)x;
}
else {
Object x = node.getItem();
if (x != null)
return (E)x;
// else cancelled, so retry
}
}
|
public java.lang.Object[] | toArray()Returns a zero-length array.
return new Object[0];
|
public T[] | toArray(T[] a)Sets the zeroeth element of the specified array to null
(if the array has non-zero length) and returns it.
if (a.length > 0)
a[0] = null;
return a;
|