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. ]

Field Summary
protected LinkedNodehead_
Dummy header node of list.
protected LinkedNodelast_
The last node of list.
protected ObjectputLock_
Helper monitor for managing access to last node.
protected intwaitingForTake_
The number of threads waiting for a take.
Constructor Summary
LinkedQueue()
Method Summary
protected Objectextract()
Main mechanics for take/poll *
protected voidinsert(Object x)
Main mechanics for put/offer *
booleanisEmpty()
booleanoffer(Object x, long msecs)
Objectpeek()
Objectpoll(long msecs)
voidput(Object x)
Objecttake()

Field Detail

head_

protected LinkedNode head_
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.

last_

protected LinkedNode last_
The last node of list. Put() appends to list, so modifies last_

putLock_

protected final Object putLock_
Helper monitor for managing access to last node.

waitingForTake_

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.

Constructor Detail

LinkedQueue

public LinkedQueue()

Method Detail

extract

protected Object extract()
Main mechanics for take/poll *

insert

protected void insert(Object x)
Main mechanics for put/offer *

isEmpty

public boolean isEmpty()

offer

public boolean offer(Object x, long msecs)

peek

public Object peek()

poll

public Object poll(long msecs)

put

public void put(Object x)

take

public Object take()