Class ProducerConsumerQueue

java.lang.Object
com.portal.common.ProducerConsumerQueue

public class ProducerConsumerQueue extends Object
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 Details

    • ProducerConsumerQueue

      public ProducerConsumerQueue()
      Create a new instance of a PC Queue
  • Method Details

    • addFirst

      public void addFirst(Object o)
      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

      public void addPriority(Object o)
      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

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

      public Object removeLast(long maxTime)
      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