Class SynchronizedQueue<E>

java.lang.Object
rs.baselib.util.SynchronizedQueue<E>

public class SynchronizedQueue<E> extends Object
Implements a thread-safe synchronized object queue that also wakes up waiting threads.
Author:
ralph
  • Field Details

    • MAX_CAPACITY

      public static final int MAX_CAPACITY
      Default number of objects to hold in this queue
      See Also:
    • available

      protected List<E> available
      The object queue
    • capacity

      protected int capacity
      The 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

      public E 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

      public void push(E o)
      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