Package rs.baselib.util
Class SynchronizedQueue<E>
java.lang.Object
rs.baselib.util.SynchronizedQueue<E>
Implements a thread-safe synchronized object queue that also wakes up waiting threads.
- Author:
- ralph
-
Field Summary
Modifier and TypeFieldDescriptionThe object queueprotected int
The maximum number of objects to be held in this queue instancestatic final int
Default number of objects to hold in this queue -
Constructor Summary
-
Method Summary
-
Field Details
-
MAX_CAPACITY
public static final int MAX_CAPACITYDefault number of objects to hold in this queue- See Also:
-
available
The object queue -
capacity
protected int capacityThe maximum number of objects to be held in this queue instance
-
-
Constructor Details
-
SynchronizedQueue
public SynchronizedQueue()Constructor.Will create the queue using
MAX_CAPACITY
as capacity. -
SynchronizedQueue
public SynchronizedQueue(int capacity) Constructor.- Parameters:
capacity
- - capacity of this queue
-
-
Method Details
-
poll
Delivers the next object from the queue.The method will block when no object is available.
Used by the reader/consumer thread.
- Returns:
- next object in queue
-
push
Adds a new object to the list of available objects.The method will block when the queue is full.
Used by the writer/producer thread.
- Parameters:
o
- - the object to be queued
-