EDU.oswego.cs.dl.util.concurrent
Class LinkedQueue
public
class
LinkedQueue
extends Object
implements Channel
A linked list based channel implementation.
The algorithm avoids contention between puts
and takes when the queue is not empty.
Normally a put and a take can proceed simultaneously.
(Although it does not allow multiple concurrent puts or takes.)
This class tends to perform more efficently than
other Channel implementations in producer/consumer
applications.
[ Introduction to this package. ]
Dummy header node of list. The first actual node, if it exists, is always
at head_.next. After each take, the old first node becomes the head.
The last node of list. Put() appends to list, so modifies last_
protected final Object putLock_
Helper monitor for managing access to last node.
protected int waitingForTake_
The number of threads waiting for a take.
Notifications are provided in put only if greater than zero.
The bookkeeping is worth it here since in reasonably balanced
usages, the notifications will hardly ever be necessary, so
the call overhead to notify can be eliminated.
public LinkedQueue()
protected Object extract()
Main mechanics for take/poll *
protected void insert(Object x)
Main mechanics for put/offer *
public boolean isEmpty()
public boolean offer(Object x, long msecs)
public Object peek()
public Object poll(long msecs)
public void put(Object x)
public Object take()