Class BlockingQueue<T>

  • All Implemented Interfaces:
    IBlockingQueue<T>

    public class BlockingQueue<T>
    extends java.lang.Object
    implements IBlockingQueue<T>
    A blocking queue allows to enqueue or dequeue elements. It blocks, when it is tried to dequeue an element, but the queue is empty.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean closed
      The queue state.
      protected java.util.List<T> elems
      The element storage.
      protected java.lang.Object monitor
      The monitor.
    • Constructor Summary

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T dequeue()
      Dequeue an element.
      T dequeue​(long timeout)
      Dequeue an element.
      void enqueue​(T element)
      Enqueue an element.
      boolean isClosed()
      Check if the queue is closed.
      static void main​(java.lang.String[] args)
      Main for testing.
      T peek()
      Peek the topmost element without dequeuing it.
      java.util.List setClosed​(boolean closed)
      Open/close the queue.
      int size()
      Return the size of the queue.
      static void test1​(java.lang.String[] args)
      Main for testing.
      static void test1b​(java.lang.String[] args)
      Main for testing.
      static void test2​(java.lang.String[] args)
      Main for testing.
      • Methods inherited from class java.lang.Object

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

      • elems

        protected java.util.List<T> elems
        The element storage.
      • closed

        protected volatile boolean closed
        The queue state.
      • monitor

        protected java.lang.Object monitor
        The monitor.
    • Constructor Detail

      • BlockingQueue

        public BlockingQueue()
        Create a blocking queue.
    • Method Detail

      • enqueue

        public void enqueue​(T element)
        Enqueue an element.
        Specified by:
        enqueue in interface IBlockingQueue<T>
        Parameters:
        element - The element.
      • isClosed

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

        public java.util.List 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.
      • size

        public int size()
        Return the size of the queue.
        Specified by:
        size in interface IBlockingQueue<T>
        Returns:
        The size.
      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.InterruptedException
        Main for testing.
        Throws:
        java.lang.InterruptedException
      • test1

        public static void test1​(java.lang.String[] args)
                          throws java.lang.InterruptedException
        Main for testing.
        Throws:
        java.lang.InterruptedException
      • test1b

        public static void test1b​(java.lang.String[] args)
                           throws java.lang.InterruptedException
        Main for testing.
        Throws:
        java.lang.InterruptedException
      • test2

        public static void test2​(java.lang.String[] args)
                          throws java.lang.InterruptedException
        Main for testing.
        Throws:
        java.lang.InterruptedException