Class MPMCBlockingQueue<E>

  • All Implemented Interfaces:
    ConcurrentQueue<E>, java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.concurrent.BlockingQueue<E>, java.util.Queue<E>

    public final class MPMCBlockingQueue<E>
    extends MPMCConcurrentQueue<E>
    implements java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.concurrent.BlockingQueue<E>, java.util.Queue<E>, ConcurrentQueue<E>
    Alternative implementation for benchmarking purposes
    See Also:
    Serialized Form
    • Field Detail

      • queueNotFullCondition

        protected final Condition queueNotFullCondition
      • queueNotEmptyCondition

        protected final Condition queueNotEmptyCondition
    • Constructor Detail

      • MPMCBlockingQueue

        public MPMCBlockingQueue​(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
      • MPMCBlockingQueue

        public MPMCBlockingQueue​(int capacity,
                                 SpinPolicy spinPolicy)

        Construct a blocking queue with a given fixed capacity

        Note: actual capacity will be the next power of two larger than capacity. Waiting locking may be used in servers that are tuned for it, waiting locking provides a high performance locking implementation which is approximately a factor of 2 improvement in throughput (40M/s for 1-1 thread transfers) However waiting locking is more CPU aggressive and causes servers that may be configured with far too many threads to show very high load averages. This is probably not as detrimental as it is annoying.
        Parameters:
        capacity - - the queue capacity, suggest using a power of 2
        spinPolicy - - determine the level of cpu aggressiveness in waiting
      • MPMCBlockingQueue

        public MPMCBlockingQueue​(int capacity,
                                 java.util.Collection<? extends E> c)

        Construct a blocking queue of the given fixed capacity

        Note: actual capacity will be the next power of two larger than capacity.

        The values from the collection, c, are appended to the queue in iteration order. If the number of elements in the collection exceeds the actual capacity, then the additional elements overwrite the previous ones until all elements have been written once.
        Parameters:
        capacity - maximum capacity of this queue
        c - A collection to use to populate inital values
    • Method Detail

      • offer

        public final boolean offer​(E e)
        Description copied from interface: ConcurrentQueue
        Add element t to the ring
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<E>
        Specified by:
        offer in interface ConcurrentQueue<E>
        Specified by:
        offer in interface java.util.Queue<E>
        Overrides:
        offer in class MPMCConcurrentQueue<E>
        Parameters:
        e - - element to offer
        Returns:
        boolean - true if the operation succeeded
      • 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>
        Overrides:
        remove in class MPMCConcurrentQueue<E>
        Parameters:
        e - - The element array
        Returns:
        int - the number of elements added to t
      • remove

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

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

        public void put​(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,
                             java.util.concurrent.TimeUnit unit)
                      throws java.lang.InterruptedException
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<E>
        Throws:
        java.lang.InterruptedException
      • take

        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()
        Specified by:
        remainingCapacity in interface java.util.concurrent.BlockingQueue<E>
      • drainTo

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

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

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<E>
      • toArray

        public <T> T[] toArray​(T[] a)
        Specified by:
        toArray in interface java.util.Collection<E>
      • add

        public boolean add​(E e)
        Specified by:
        add in interface java.util.concurrent.BlockingQueue<E>
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add 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>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> c)
        Specified by:
        containsAll in interface java.util.Collection<E>
      • addAll

        public boolean addAll​(java.util.Collection<? extends E> c)
        Specified by:
        addAll in interface java.util.Collection<E>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<E>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<E>
      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
      • isFull

        private final boolean isFull()