Top Description Inners Fields Constructors Methods
EDU.oswego.cs.dl.util.concurrent

public Class SynchronousChannel

extends Object
implements BoundedChannel
Class Inheritance
All Implemented Interfaces
EDU.oswego.cs.dl.util.concurrent.BoundedChannel, EDU.oswego.cs.dl.util.concurrent.Channel, EDU.oswego.cs.dl.util.concurrent.Takable, EDU.oswego.cs.dl.util.concurrent.Puttable

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.

See Also
Introduction to this package., CyclicBarrier, Rendezvous

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
SynchronousChannel.Queue

Simple FIFO queue class to hold waiting puts/takes.

Field Summary

Modifier and TypeField and Description
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.

protected final SynchronousChannel.Queue
protected final SynchronousChannel.Queue

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

zero -- Synchronous channels have no internal capacity.
capacity
()

Implements EDU.oswego.cs.dl.util.concurrent.BoundedChannel.capacity.

Return the maximum number of elements that can be held.
public boolean
offer(Object
the element to be inserted. Should be non-null.
x
,
long
the number of milliseconds to wait. If less than or equal to zero, the method does not perform any timed waits, but might still require access to a synchronization lock, which can impose unbounded delay if there is a lot of contention for the channel.
msecs
)

Implements EDU.oswego.cs.dl.util.concurrent.Channel.offer.

Place item in channel only if it can be accepted within msecs milliseconds.
public Object

Returns:

null -- Synchronous channels do not hold contents unless actively taken
peek
()

Implements EDU.oswego.cs.dl.util.concurrent.Channel.peek.

Return, but do not remove object at head of Channel, or null if it is empty.
public Object
poll(long
the number of milliseconds to wait. If less than or equal to zero, the operation does not perform any timed waits, but might still require access to a synchronization lock, which can impose unbounded delay if there is a lot of contention for the channel.
msecs
)

Implements EDU.oswego.cs.dl.util.concurrent.Channel.poll.

Return and remove an item from channel only if one is available within msecs milliseconds.
public void
put(Object
the element to be inserted. Should be non-null.
x
)

Implements EDU.oswego.cs.dl.util.concurrent.Channel.put.

Place item in the channel, possibly waiting indefinitely until it can be accepted.
public Object
take()

Implements EDU.oswego.cs.dl.util.concurrent.Channel.take.

Return and remove an item from channel, possibly waiting indefinitely until such an item exists.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CANCELLEDback to summary
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.

waitingPutsback to summary
protected final SynchronousChannel.Queue waitingPuts
waitingTakesback to summary
protected final SynchronousChannel.Queue waitingTakes

Constructor Detail

SynchronousChannelback to summary
public SynchronousChannel()

Method Detail

capacityback to summary
public int capacity()

Implements EDU.oswego.cs.dl.util.concurrent.BoundedChannel.capacity.

Doc from EDU.oswego.cs.dl.util.concurrent.BoundedChannel.capacity.

Return the maximum number of elements that can be held.

Returns:int

zero -- Synchronous channels have no internal capacity.

offerback to summary
public boolean offer(Object x, long msecs) throws InterruptedException

Implements EDU.oswego.cs.dl.util.concurrent.Channel.offer.

Doc from EDU.oswego.cs.dl.util.concurrent.Channel.offer.

Place item in channel only if it can be accepted within msecs milliseconds. The time bound is interpreted in a coarse-grained, best-effort fashion.

Parameters
x:Object

the element to be inserted. Should be non-null.

msecs:long

the number of milliseconds to wait. If less than or equal to zero, the method does not perform any timed waits, but might still require access to a synchronization lock, which can impose unbounded delay if there is a lot of contention for the channel.

Returns:boolean

true if accepted, else false

Exceptions
InterruptedException:
if the current thread has been interrupted at a point at which interruption is detected, in which case the element is guaranteed not to be inserted (i.e., is equivalent to a false return).
peekback to summary
public Object peek()

Implements EDU.oswego.cs.dl.util.concurrent.Channel.peek.

Doc from EDU.oswego.cs.dl.util.concurrent.Channel.peek.

Return, but do not remove object at head of Channel, or null if it is empty.

Returns:Object

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

pollback to summary
public Object poll(long msecs) throws InterruptedException

Implements EDU.oswego.cs.dl.util.concurrent.Channel.poll.

Doc from EDU.oswego.cs.dl.util.concurrent.Channel.poll.

Return and remove an item from channel only if one is available within msecs milliseconds. The time bound is interpreted in a coarse grained, best-effort fashion.

Parameters
msecs:long

the number of milliseconds to wait. If less than or equal to zero, the operation does not perform any timed waits, but might still require access to a synchronization lock, which can impose unbounded delay if there is a lot of contention for the channel.

Returns:Object

some item, or null if the channel is empty.

Exceptions
InterruptedException:
if the current thread has been interrupted at a point at which interruption is detected, in which case state of the channel is unchanged (i.e., equivalent to a null return).
putback to summary
public void put(Object x) throws InterruptedException

Implements EDU.oswego.cs.dl.util.concurrent.Channel.put.

Doc from EDU.oswego.cs.dl.util.concurrent.Channel.put.

Place item in the channel, possibly waiting indefinitely until it can be accepted. Channels implementing the BoundedChannel subinterface are generally guaranteed to block on puts upon reaching capacity, but other implementations may or may not block.

Parameters
x:Object

the element to be inserted. Should be non-null.

Exceptions
InterruptedException:
if the current thread has been interrupted at a point at which interruption is detected, in which case the element is guaranteed not to be inserted. Otherwise, on normal return, the element is guaranteed to have been inserted.
takeback to summary
public Object take() throws InterruptedException

Implements EDU.oswego.cs.dl.util.concurrent.Channel.take.

Doc from EDU.oswego.cs.dl.util.concurrent.Channel.take.

Return and remove an item from channel, possibly waiting indefinitely until such an item exists.

Returns:Object

some item from the channel. Different implementations may guarantee various properties (such as FIFO) about that item

Exceptions
InterruptedException:
if the current thread has been interrupted at a point at which interruption is detected, in which case state of the channel is unchanged.
EDU.oswego.cs.dl.util.concurrent back to summary

protected Class SynchronousChannel.Queue

extends Object
Class Inheritance

Simple FIFO queue class to hold waiting puts/takes.

Field Summary

Modifier and TypeField and Description
protected LinkedNode
protected LinkedNode

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected LinkedNode
deq()

protected void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

headback to summary
protected LinkedNode head
lastback to summary
protected LinkedNode last

Constructor Detail

Queueback to summary
protected Queue()

Method Detail

deqback to summary
protected LinkedNode deq()
enqback to summary
protected void enq(LinkedNode p)