Class ManyToOneConcurrentLinkedQueue<E>

java.lang.Object
org.agrona.concurrent.ManyToOneConcurrentLinkedQueue<E>
Type Parameters:
E - element type in the queue.
All Implemented Interfaces:
Iterable<E>, Collection<E>, Queue<E>

public class ManyToOneConcurrentLinkedQueue<E> extends Object implements Queue<E>
Concurrent linked Queue that can be used from many producers and a single consumer.

This is a Java port of Dmitry Vyukov's MPSC linked queue.

Note: This queue breaks the contract for peek and poll in that it can return null when the queue has no item available but size could be greater than zero if an offer is in progress. This is due to the offer being a multiple step process which can start and be interrupted before completion, the thread will later be resumed and the offer process completes. Other methods, such as peek and poll, could spin internally waiting on the offer to complete to provide sequentially consistency across methods but this can have a detrimental effect in a resource starved system. This internal spinning eats up a CPU core and prevents other threads making progress resulting in latency spikes. To avoid this a more relaxed approach is taken in that an in-progress offer is not waited on to complete.

If you wish to check for empty then call isEmpty() rather than size() checking for zero.

  • Field Details

    • tail

      protected volatile org.agrona.concurrent.ManyToOneConcurrentLinkedQueuePadding1.Node<E> tail
      Tail of the queue.
    • HEAD_OFFSET

      protected static final long HEAD_OFFSET
      Offset of the head field.
    • TAIL_OFFSET

      protected static final long TAIL_OFFSET
      Offset of the tail field.
    • NEXT_OFFSET

      protected static final long NEXT_OFFSET
      Offset of the next field.
  • Constructor Details

    • ManyToOneConcurrentLinkedQueue

      public ManyToOneConcurrentLinkedQueue()
      Constructs an empty queue.
  • Method Details