Class MPMCConcurrentQueue<E>

  • All Implemented Interfaces:
    ConcurrentQueue<E>
    Direct Known Subclasses:
    MPMCBlockingQueue

    class MPMCConcurrentQueue<E>
    extends java.lang.Object
    implements ConcurrentQueue<E>
    Dmitry Vyukov, Bounded MPMC queue - http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue Added for benchmarking and comparison. MultithreadConcurrentQueue performs better in the regimes I have tested. Created by jcairns on 5/29/14.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static class  MPMCConcurrentQueue.Cell<R>  
    • Constructor Summary

      Constructors 
      Constructor Description
      MPMCConcurrentQueue​(int capacity)
      Construct a blocking queue of the given fixed capacity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int capacity()  
      void clear()
      clear the queue of all elements
      boolean contains​(java.lang.Object o)  
      boolean isEmpty()  
      boolean offer​(E e)
      Add element t to the ring
      E peek()
      return the first element in the queue
      E poll()
      remove the first element from the queue and return it
      int remove​(E[] e)
      return all elements in the queue to the provided array, up to the size of the provided array.
      int size()  
      • Methods inherited from class java.lang.Object

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

      • MPMCConcurrentQueue

        public MPMCConcurrentQueue​(int capacity)
        Construct a blocking queue of the given fixed capacity. Note: actual capacity will be the next power of two larger than capacity.
        Parameters:
        capacity - maximum capacity of this queue
    • Method Detail

      • offer

        public boolean offer​(E e)
        Description copied from interface: ConcurrentQueue
        Add element t to the ring
        Specified by:
        offer in interface ConcurrentQueue<E>
        Parameters:
        e - - element to offer
        Returns:
        boolean - true if the operation succeeded
      • poll

        public E poll()
        Description copied from interface: ConcurrentQueue
        remove the first element from the queue and return it
        Specified by:
        poll in interface ConcurrentQueue<E>
        Returns:
        T
      • peek

        public final E peek()
        Description copied from interface: ConcurrentQueue
        return the first element in the queue
        Specified by:
        peek in interface ConcurrentQueue<E>
        Returns:
        E - The element
      • remove

        public int remove​(E[] e)
        Description copied from interface: ConcurrentQueue
        return all elements in the queue to the provided array, up to the size of the provided array.
        Specified by:
        remove in interface ConcurrentQueue<E>
        Parameters:
        e - - The element array
        Returns:
        int - the number of elements added to t
      • size

        public final int size()
        Specified by:
        size in interface ConcurrentQueue<E>
        Returns:
        int - the number of elements in the queue
      • capacity

        public int capacity()
        Specified by:
        capacity in interface ConcurrentQueue<E>
        Returns:
        int - the capacity of the queue
      • isEmpty

        public final boolean isEmpty()
        Specified by:
        isEmpty in interface ConcurrentQueue<E>
        Returns:
        boolean - true if the queue is currently empty
      • contains

        public final boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface ConcurrentQueue<E>
        Parameters:
        o - - the object to test
        Returns:
        boolean - true if specified object is contained in the queue