Package rs.baselib.util
Class SynchronizedQueue<E>
java.lang.Object
rs.baselib.util.SynchronizedQueue<E>
public class SynchronizedQueue<E>
extends java.lang.Object
Implements a thread-safe synchronized object queue that also wakes up waiting threads.
- Author:
- ralph
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<E>availableThe object queueprotected intcapacityThe maximum number of objects to be held in this queue instancestatic intMAX_CAPACITYDefault number of objects to hold in this queue -
Constructor Summary
Constructors Constructor Description SynchronizedQueue()Constructor.SynchronizedQueue(int capacity)Constructor. -
Method Summary
-
Field Details
-
MAX_CAPACITY
public static final int MAX_CAPACITYDefault number of objects to hold in this queue- See Also:
- Constant Field Values
-
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_CAPACITYas 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
-