Package 

Class ArrayBlockingQueueWithShutdown

  • All Implemented Interfaces:
    java.lang.Iterable , java.util.Collection , java.util.Queue , java.util.concurrent.BlockingQueue

    
    public class ArrayBlockingQueueWithShutdown<E>
    extends AbstractQueue<E> implements BlockingQueue<E>
                        

    Like ArrayBlockingQueue but with additional shutdown and start methods. Will throw InterruptedException if Queue has been shutdown on take and poll.

    Based on ArrayBlockingQueue of OpenJDK by Doug Lea (who released ArrayBlockingQueue as public domain). Imported from Smack Core 4.2.4.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private volatile boolean isShutdown
    • Method Summary

      Modifier and Type Method Description
      boolean isShutdown() Returns true if the queue is currently shut down.
      void shutdown() Shutdown the Queue.
      void start() Start the queue.
      E poll()
      E peek()
      boolean offer(E e)
      void put(E e) Inserts the specified element into this queue, waiting if necessaryfor space to become available.
      boolean offer(E e, long timeout, TimeUnit unit)
      E take()
      E poll(long timeout, TimeUnit unit)
      int remainingCapacity()
      int drainTo(Collection<out Object> c)
      int drainTo(Collection<out Object> c, int maxElements)
      int size()
      Iterator<E> iterator()
      • Methods inherited from class java.util.AbstractQueue

        add, addAll, clear, element, remove
      • Methods inherited from class java.util.AbstractCollection

        contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
      • Methods inherited from class java.util.Collection

        parallelStream, removeIf, spliterator, stream
      • Methods inherited from class java.lang.Iterable

        forEach, iterator, spliterator
      • Methods inherited from class java.util.Queue

        offer, peek, poll
      • Methods inherited from class java.util.concurrent.BlockingQueue

        drainTo, put, remainingCapacity, take
      • Methods inherited from class java.lang.Object

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

      • ArrayBlockingQueueWithShutdown

        ArrayBlockingQueueWithShutdown(int capacity)
      • ArrayBlockingQueueWithShutdown

        ArrayBlockingQueueWithShutdown(int capacity, boolean fair)
    • Method Detail

      • isShutdown

         boolean isShutdown()

        Returns true if the queue is currently shut down.

      • shutdown

         void shutdown()

        Shutdown the Queue. Will method currently waiting for a not full/empty condition will unblock(and usually throw a InterruptedException).

      • start

         void start()

        Start the queue. Newly created instances will be started automatically, thus this only needsto be called after shutdown.

      • put

         void put(E e)

        Inserts the specified element into this queue, waiting if necessaryfor space to become available.

        This may throw an InterruptedException in two cases

        • If the queue was shut down.
        • If the thread was was interrupted.
        So you have to check which is the case, e.g. by calling isShutdown.
        Parameters:
        e - the element to add.