|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection
java.util.AbstractQueue
java.util.concurrent.SynchronousQueue
A blocking queue in which each put must wait for a take, and vice versa. A synchronous queue does not have any internal capacity - in particular it does not have a capacity of one. You cannot peek at a synchronous queue because an element is only present when you try to take it; you cannot add an element (using any method) unless another thread is trying to remove it; you cannot iterate as there is nothing to iterate. The head of the queue is the element that the first queued thread is trying to add to the queue; if there are no queued threads then no element is being added and the head is null. For purposes of other Collection methods (for example contains), a SynchronousQueue acts as an empty collection. This queue does not permit null elements.
Synchronous queues are similar to rendezvous channels used in CSP and Ada. They are well suited for handoff designs, in which an object running in one thread must synch up with an object running in another thread in order to hand it some information, event, or task.
This class implements all of the optional methods
of the Collection and Iterator interfaces.
| Constructor Summary | |
SynchronousQueue()
Creates a SynchronousQueue. |
|
| Method Summary | ||
void |
clear()
Does nothing. |
|
boolean |
contains(java.lang.Object o)
Always returns false. |
|
boolean |
containsAll(Collection<?> c)
Returns false unless given collection is empty. |
|
boolean |
isEmpty()
Always returns true. |
|
Iterator<E> |
iterator()
Returns an empty iterator in which hasNext always returns false. |
|
boolean |
offer(E o)
Inserts the specified element into this queue, if another thread is waiting to receive it. |
|
boolean |
offer(E o,
long timeout,
TimeUnit unit)
Inserts the specified element into this queue, waiting if necessary up to the specified wait time for another thread to receive it. |
|
E |
peek()
Always returns null. |
|
E |
poll()
Retrieves and removes the head of this queue, if another thread is currently making an element available. |
|
E |
poll(long timeout,
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. |
|
void |
put(E o)
Adds the specified element to this queue, waiting if necessary for another thread to receive it. |
|
int |
remainingCapacity()
Always returns zero. |
|
boolean |
remove(java.lang.Object o)
Always returns false. |
|
boolean |
removeAll(Collection<?> c)
Always returns false. |
|
boolean |
retainAll(Collection<?> c)
Always returns false. |
|
int |
size()
Always returns zero. |
|
E |
take()
Retrieves and removes the head of this queue, waiting if necessary for another thread to insert it. |
|
java.lang.Object[] |
toArray()
Returns a zero-length array. |
|
|
toArray(T[] a)
Sets the zeroeth element of the specified array to null (if the array has non-zero length) and returns it. |
|
| Methods inherited from class java.util.AbstractQueue |
add, element, remove |
| Methods inherited from class java.util.AbstractCollection |
addAll, toString |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.concurrent.BlockingQueue |
add, addAll |
| Methods inherited from interface java.util.Queue |
element, remove |
| Methods inherited from interface java.util.Collection |
equals, hashCode |
| Constructor Detail |
public SynchronousQueue()
| Method Detail |
public void put(E o)
throws java.lang.InterruptedException
put in interface BlockingQueueo - the element to add
java.lang.InterruptedException - if interrupted while waiting.
java.lang.NullPointerException - if the specified element is null.
public boolean offer(E o,
long timeout,
TimeUnit unit)
throws java.lang.InterruptedException
offer in interface BlockingQueueo - the element to addtimeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameter
java.lang.InterruptedException - if interrupted while waiting.
java.lang.NullPointerException - if the specified element is null.
public E take()
throws java.lang.InterruptedException
take in interface BlockingQueuejava.lang.InterruptedException - if interrupted while waiting.
public E poll(long timeout,
TimeUnit unit)
throws java.lang.InterruptedException
poll in interface BlockingQueuetimeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameter
java.lang.InterruptedException - if interrupted while waiting.public boolean offer(E o)
offer in interface BlockingQueueo - the element to add.
java.lang.NullPointerException - if the specified element is nullpublic E poll()
poll in interface Queuepublic boolean isEmpty()
isEmpty in interface CollectionisEmpty in class AbstractCollectionpublic int size()
size in interface Collectionsize in class AbstractCollectionpublic int remainingCapacity()
remainingCapacity in interface BlockingQueuepublic void clear()
clear in interface Collectionclear in class AbstractQueuepublic boolean contains(java.lang.Object o)
contains in interface Collectioncontains in class AbstractCollectiono - the element
public boolean remove(java.lang.Object o)
remove in interface Collectionremove in class AbstractCollectiono - the element to remove
public boolean containsAll(Collection<?> c)
containsAll in interface CollectioncontainsAll in class AbstractCollectionc - the collection
AbstractCollection.contains(Object)public boolean removeAll(Collection<?> c)
removeAll in interface CollectionremoveAll in class AbstractCollectionc - the collection
AbstractCollection.remove(Object),
AbstractCollection.contains(Object)public boolean retainAll(Collection<?> c)
retainAll in interface CollectionretainAll in class AbstractCollectionc - the collection
AbstractCollection.remove(Object),
AbstractCollection.contains(Object)public E peek()
peek in interface Queuepublic Iterator<E> iterator()
iterator in interface Collectioniterator in class AbstractCollectionpublic java.lang.Object[] toArray()
toArray in interface CollectiontoArray in class AbstractCollectionpublic <T> T[] toArray(T[] a)
toArray in interface CollectiontoArray in class AbstractCollectiona - the array into which the elements of the collection are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||