Class ConcurrentLinkedBlockingQueue<E>

  • Type Parameters:
    E - content type
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.concurrent.BlockingQueue<E>, java.util.Queue<E>

    public class ConcurrentLinkedBlockingQueue<E>
    extends java.util.AbstractQueue<E>
    implements java.util.concurrent.BlockingQueue<E>
    A BlockingQueue implementation which uses a collection of concurrent Queues per thread in order to reduce the hotspot of a highly contended mutex or atomic reference.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      int drainTo​(java.util.Collection<? super E> c)
      int drainTo​(java.util.Collection<? super E> c, int maxElements)
      boolean isEmpty()
      java.util.Iterator<E> iterator()
      protected java.util.Queue<E> newQueue()
      Create a new single-producer multiple-consumer thread-safe queue
      boolean offer​(E e)
      boolean offer​(E e, long timeout, java.util.concurrent.TimeUnit unit)
      E peek()
      E poll()
      E poll​(long timeout, java.util.concurrent.TimeUnit unit)
      void put​(E e)
      int remainingCapacity()
      Returns Integer.MAX_VALUE because this is an unbounded queue.
      boolean remove​(java.lang.Object o)
      boolean removeIf​(java.util.function.Predicate<? super E> filter)
      int size()
      E take()
      • Methods inherited from class java.util.AbstractQueue

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

        contains, containsAll, removeAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.concurrent.BlockingQueue

        add, contains
      • Methods inherited from interface java.util.Collection

        addAll, containsAll, equals, hashCode, parallelStream, removeAll, retainAll, spliterator, stream, toArray, toArray, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Queue

        element, remove
    • Constructor Detail

      • ConcurrentLinkedBlockingQueue

        public ConcurrentLinkedBlockingQueue()
        Default constructor with a pollSleepMillis of 10 milliseconds.
      • ConcurrentLinkedBlockingQueue

        public ConcurrentLinkedBlockingQueue​(@Nonnegative
                                             long pollSleepMillis)
        Constructor which permits specifying the pollSleepMillis
        Parameters:
        pollSleepMillis - the number of milliseconds that a poller should sleep while waiting.
    • Method Detail

      • newQueue

        protected java.util.Queue<E> newQueue()
        Create a new single-producer multiple-consumer thread-safe queue
        Returns:
        new queue instance.
      • iterator

        @Nonnull
        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Overrides:
        isEmpty in class java.util.AbstractCollection<E>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Overrides:
        clear in class java.util.AbstractQueue<E>
      • put

        public void put​(@Nonnull
                        E e)
                 throws java.lang.InterruptedException
        Specified by:
        put in interface java.util.concurrent.BlockingQueue<E>
        Throws:
        java.lang.InterruptedException
      • offer

        public boolean offer​(E e,
                             long timeout,
                             @Nonnull
                             java.util.concurrent.TimeUnit unit)
                      throws java.lang.InterruptedException
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<E>
        Throws:
        java.lang.InterruptedException
      • take

        @Nonnull
        public E take()
               throws java.lang.InterruptedException
        Specified by:
        take in interface java.util.concurrent.BlockingQueue<E>
        Throws:
        java.lang.InterruptedException
      • poll

        public E poll​(long timeout,
                      java.util.concurrent.TimeUnit unit)
               throws java.lang.InterruptedException
        Specified by:
        poll in interface java.util.concurrent.BlockingQueue<E>
        Throws:
        java.lang.InterruptedException
      • remainingCapacity

        public int remainingCapacity()
        Returns Integer.MAX_VALUE because this is an unbounded queue.
        Specified by:
        remainingCapacity in interface java.util.concurrent.BlockingQueue<E>
      • drainTo

        public int drainTo​(@Nonnull
                           java.util.Collection<? super E> c)
        Specified by:
        drainTo in interface java.util.concurrent.BlockingQueue<E>
      • drainTo

        public int drainTo​(@Nonnull
                           java.util.Collection<? super E> c,
                           int maxElements)
        Specified by:
        drainTo in interface java.util.concurrent.BlockingQueue<E>
      • offer

        public boolean offer​(E e)
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<E>
        Specified by:
        offer in interface java.util.Queue<E>
      • poll

        public E poll()
        Specified by:
        poll in interface java.util.Queue<E>
      • peek

        public E peek()
        Specified by:
        peek in interface java.util.Queue<E>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.concurrent.BlockingQueue<E>
        Specified by:
        remove in interface java.util.Collection<E>
        Overrides:
        remove in class java.util.AbstractCollection<E>
      • removeIf

        public boolean removeIf​(java.util.function.Predicate<? super E> filter)
        Specified by:
        removeIf in interface java.util.Collection<E>