Class SpscUnboundedAtomicArrayQueue<T>

  • All Implemented Interfaces:
    Iterable<T>, Collection<T>, Queue<T>


    public final class SpscUnboundedAtomicArrayQueue<T>
    extends Object
    implements Queue<T>
    A single-producer single-consumer queue with unbounded capacity.

    The implementation uses fixed, power-of-2 arrays to store elements and turns into a linked-list like structure if the production overshoots the consumption.

    Note that the minimum capacity of the 'islands' are 8 due to how the look-ahead optimization works.

    The implementation uses field updaters and thus should be platform-safe.

    • Field Detail

      • producerIndex

        protected volatile long producerIndex
      • producerLookAheadStep

        protected int producerLookAheadStep
      • producerLookAhead

        protected long producerLookAhead
      • producerMask

        protected int producerMask
      • consumerMask

        protected int consumerMask
      • consumerIndex

        protected volatile long consumerIndex
    • Constructor Detail

      • SpscUnboundedAtomicArrayQueue

        public SpscUnboundedAtomicArrayQueue(int bufferSize)
    • Method Detail

      • offer

        public final boolean offer(T e)

        This implementation is correct for single producer thread use only.

      • poll

        public final T poll()

        This implementation is correct for single consumer thread use only.

      • peek

        public final T peek()

        This implementation is correct for single consumer thread use only.

      • clear

        public void clear()
      • size

        public final int size()
      • isEmpty

        public boolean isEmpty()
      • iterator

        public final Iterator<T> iterator()
      • contains

        public boolean contains(Object o)
      • toArray

        public Object[] toArray()
      • toArray

        public <E> E[] toArray(E[] a)
      • remove

        public boolean remove(Object o)
      • containsAll

        public boolean containsAll(Collection<?> c)
      • addAll

        public boolean addAll(Collection<? extends T> c)
      • removeAll

        public boolean removeAll(Collection<?> c)
      • retainAll

        public boolean retainAll(Collection<?> c)
      • add

        public boolean add(T e)
      • remove

        public T remove()
      • element

        public T element()