EDU.oswego.cs.dl.util.concurrent

Class SynchronousChannel

public class SynchronousChannel extends Object implements BoundedChannel

A rendezvous channel, similar to those used in CSP and Ada. Each put must wait for a take, and vice versa. Synchronous channels 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.

If you only need threads to synch up without exchanging information, consider using a Barrier. If you need bidirectional exchanges, consider using a Rendezvous.

[ Introduction to this package. ]

See Also: CyclicBarrier

Nested Class Summary
protected static classSynchronousChannel.Queue
Simple FIFO queue class to hold waiting puts/takes.
Field Summary
protected static ObjectCANCELLED
Special marker used in queue nodes to indicate that the thread waiting for a change in the node has timed out or been interrupted.
protected SynchronousChannel.QueuewaitingPuts
protected SynchronousChannel.QueuewaitingTakes
Method Summary
intcapacity()
booleanoffer(Object x, long msecs)
Objectpeek()
Objectpoll(long msecs)
voidput(Object x)
Objecttake()

Field Detail

CANCELLED

protected static final Object CANCELLED
Special marker used in queue nodes to indicate that the thread waiting for a change in the node has timed out or been interrupted.

waitingPuts

protected final SynchronousChannel.Queue waitingPuts

waitingTakes

protected final SynchronousChannel.Queue waitingTakes

Method Detail

capacity

public int capacity()

Returns: zero -- Synchronous channels have no internal capacity.

offer

public boolean offer(Object x, long msecs)

peek

public Object peek()

Returns: null -- Synchronous channels do not hold contents unless actively taken

poll

public Object poll(long msecs)

put

public void put(Object x)

take

public Object take()