Package com.portal.common
Class ProducerConsumerQueue
java.lang.Object
com.portal.common.ProducerConsumerQueue
An implementation of a ProducerConsumerQueue - often used to pass
messages and data between threads
- Version:
- %version: 1 % %date_modified: Tue Jul 20 21:33:24 1999 %
- Author:
- larrylf
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a new object to the queue (Produce).void
Add a new object to the queue giving it priorty.boolean
Returns true if there are Consumer threads waiting for objects.Remove an object from the queue (Consume).removeLast
(long maxTime) Remove an object from the queue (Consume).int
size()
Returns the number of objects on the PCQueue.
-
Constructor Details
-
ProducerConsumerQueue
public ProducerConsumerQueue()Create a new instance of a PC Queue
-
-
Method Details
-
addFirst
Add a new object to the queue (Produce). PCQueues follow Quque (FIFO) symantics, so new items are added to one end, and removed from the other. If one or more Consumer threads are waiting, one will be notified.- Parameters:
o
- Object to add to the queue
-
addPriority
Add a new object to the queue giving it priorty. This will be the next object fetched by a Consumer unless another priority object is produced before one is consumed. Priority objects follow Stack symantics (FILO), and all priority items will be consumed before non-priority objects If one or more Consumer threads are waiting, one will be notified.- Parameters:
o
- Object to add to the queue
-
removeLast
Remove an object from the queue (Consume). If the queue is empty, the calling thread will block until an object is available before returning.- Returns:
- An object from the queue.
-
removeLast
Remove an object from the queue (Consume). If the queue is empty, the calling thread will block until an object is available or until the specified time passes before returning. Null will be returned if a timeout occures.- Parameters:
maxTime
- THe maximum time to wait for an Object in milliseconds- Returns:
- An object from the queue.
-
hasWaiters
public boolean hasWaiters()Returns true if there are Consumer threads waiting for objects.- Returns:
- true if there are waiting consumers
-
size
public int size()Returns the number of objects on the PCQueue. Subject to race conditions- Returns:
- The number of object on the PCQueue
-