edu.emory.mathcs.backport.java.util.concurrent
public class SynchronousQueue extends AbstractQueue implements BlockingQueue, Serializable
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 sync up with an object running in another thread in order to hand it some information, event, or task.
This class supports an optional fairness policy for ordering waiting producer and consumer threads. By default, this ordering is not guaranteed. However, a queue constructed with fairness set to true grants threads access in FIFO order. Fairness generally decreases throughput but reduces variability and avoids starvation.
This class and its iterator implement all of the optional methods of the Collection and Iterator interfaces.
This class is a member of the Java Collections Framework.
Since: 1.5
Constructor Summary | |
---|---|
SynchronousQueue()
Creates a SynchronousQueue with nonfair access policy. | |
SynchronousQueue(boolean fair)
Creates a SynchronousQueue with specified fairness policy. |
Method Summary | |
---|---|
void | clear()
Does nothing.
|
boolean | contains(Object o)
Always returns false.
|
boolean | containsAll(Collection c)
Returns false unless the given collection is empty.
|
int | drainTo(Collection c) |
int | drainTo(Collection c, int maxElements) |
boolean | isEmpty()
Always returns true.
|
Iterator | iterator()
Returns an empty iterator in which hasNext always returns
false.
|
boolean | offer(Object e, 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.
|
boolean | offer(Object e)
Inserts the specified element into this queue, if another thread is
waiting to receive it.
|
Object | peek()
Always returns null.
|
Object | 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.
|
Object | poll()
Retrieves and removes the head of this queue, if another thread
is currently making an element available.
|
void | put(Object e)
Adds the specified element to this queue, waiting if necessary for
another thread to receive it.
|
int | remainingCapacity()
Always returns zero.
|
boolean | remove(Object o)
Always returns false.
|
boolean | removeAll(Collection c)
Always returns false.
|
boolean | retainAll(Collection c)
Always returns false.
|
int | size()
Always returns zero.
|
Object | take()
Retrieves and removes the head of this queue, waiting if necessary
for another thread to insert it.
|
Object[] | toArray()
Returns a zero-length array. |
Object[] | toArray(Object[] a)
Sets the zeroeth element of the specified array to null
(if the array has non-zero length) and returns it.
|
Parameters: fair if true, threads contend in FIFO order for access; otherwise the order is unspecified.
Parameters: o object to be checked for containment in this queue
Returns: false
Parameters: c the collection
Returns: false unless the given collection is empty
Throws: NullPointerException if the specified collection is null
Throws: UnsupportedOperationException {@inheritDoc } ClassCastException {@inheritDoc } NullPointerException {@inheritDoc } IllegalArgumentException {@inheritDoc }
Throws: UnsupportedOperationException {@inheritDoc } ClassCastException {@inheritDoc } NullPointerException {@inheritDoc } IllegalArgumentException {@inheritDoc }
Returns: true
Returns: an empty iterator
Returns: true if successful, or false if the specified waiting time elapses before a consumer appears.
Throws: InterruptedException {@inheritDoc } NullPointerException {@inheritDoc }
Parameters: e the element to add
Returns: true if the element was added to this queue, else false
Throws: NullPointerException if the specified element is null
Returns: null
Returns: the head of this queue, or null if the specified waiting time elapses before an element is present.
Throws: InterruptedException {@inheritDoc }
Returns: the head of this queue, or null if no element is available.
Throws: InterruptedException {@inheritDoc } NullPointerException {@inheritDoc }
Returns: zero
Parameters: o the element to remove
Returns: false
Parameters: c the collection
Returns: false
Parameters: c the collection
Returns: false
Returns: zero
Returns: the head of this queue
Throws: InterruptedException {@inheritDoc }
Returns: a zero-length array
Parameters: a the array
Returns: the specified array
Throws: NullPointerException if the specified array is null