Class ArrayBlockingQueue<T>

  • All Implemented Interfaces:
    IBlockingQueue<T>

    public class ArrayBlockingQueue<T>
    extends java.lang.Object
    implements IBlockingQueue<T>
    Blocking queue implemented as array. The array is expanded automatically when the queue grows.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean closed
      The queue state.
      protected java.lang.Object[] elements
      The elements in the queue.
      protected int end
      Insert position for the next element.
      protected java.lang.Object monitor
      The monitor.
      protected int size
      The size (cached for speed).
      protected int start
      Pointer to the first element.
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayBlockingQueue()
      Create a new blocking queue.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T dequeue()
      Remove an object from the queue (blocks until an element is available).
      T dequeue​(long timeout)
      Dequeue an element.
      void enqueue​(java.lang.Object o)
      Add an element to the end of the queue.
      boolean isClosed()
      Check if the queue is closed.
      T peek()
      Peek the topmost element without dequeuing it.
      java.util.List<T> setClosed​(boolean closed)
      Open/close the queue.
      int size()
      Get the number of elements in the queue.
      java.lang.String toString()
      Create a string representation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • elements

        protected java.lang.Object[] elements
        The elements in the queue.
      • start

        protected int start
        Pointer to the first element.
      • end

        protected int end
        Insert position for the next element.
      • size

        protected int size
        The size (cached for speed).
      • monitor

        protected java.lang.Object monitor
        The monitor.
      • closed

        protected boolean closed
        The queue state.
    • Constructor Detail

      • ArrayBlockingQueue

        public ArrayBlockingQueue()
        Create a new blocking queue.
    • Method Detail

      • size

        public int size()
        Get the number of elements in the queue.
        Specified by:
        size in interface IBlockingQueue<T>
        Returns:
        The size.
      • enqueue

        public void enqueue​(java.lang.Object o)
        Add an element to the end of the queue.
        Specified by:
        enqueue in interface IBlockingQueue<T>
        Parameters:
        o - The element.
      • dequeue

        public T dequeue()
        Remove an object from the queue (blocks until an element is available).
        Specified by:
        dequeue in interface IBlockingQueue<T>
        Returns:
        The element. When queue is empty the methods blocks until an element is added.
      • setClosed

        public java.util.List<T> setClosed​(boolean closed)
        Open/close the queue.
        Specified by:
        setClosed in interface IBlockingQueue<T>
        Parameters:
        closed - The closed state.
        Returns:
        The remaining elements after the queue has been closed.
      • isClosed

        public boolean isClosed()
        Check if the queue is closed.
        Specified by:
        isClosed in interface IBlockingQueue<T>
      • toString

        public java.lang.String toString()
        Create a string representation.
        Overrides:
        toString in class java.lang.Object