Class LinkedTransferQueue<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
com.google.code.yanf4j.util.LinkedTransferQueue<E>
Type Parameters:
E - the type of elements held in this collection
All Implemented Interfaces:
Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>
Direct Known Subclasses:
FlowControlLinkedTransferQueue

public class LinkedTransferQueue<E> extends AbstractQueue<E> implements BlockingQueue<E>
An unbounded TransferQueue based on linked nodes. This queue orders elements FIFO (first-in-first-out) with respect to any given producer. The head of the queue is that element that has been on the queue the longest time for some producer. The tail of the queue is that element that has been on the queue the shortest time for some producer.

Beware that, unlike in most collections, the size method is NOT a constant-time operation. Because of the asynchronous nature of these queues, determining the current number of elements requires a traversal of the elements.

This class and its iterator implement all of the optional methods of the Collection and Iterator interfaces.

Memory consistency effects: As with other concurrent collections, actions in a thread prior to placing an object into a LinkedTransferQueue happen-before actions subsequent to the access or removal of that element from the LinkedTransferQueue in another thread.

  • Field Details

    • NOWAIT

      private static final int NOWAIT
      See Also:
    • TIMEOUT

      private static final int TIMEOUT
      See Also:
    • WAIT

      private static final int WAIT
      See Also:
    • NCPUS

      private static final int NCPUS
      The number of CPUs, for spin control
    • maxTimedSpins

      private static final int maxTimedSpins
      The number of times to spin before blocking in timed waits. The value is empirically derived -- it works well across a variety of processors and OSes. Empirically, the best value seems not to vary with number of CPUs (beyond 2) so is just a constant.
    • maxUntimedSpins

      private static final int maxUntimedSpins
      The number of times to spin before blocking in untimed waits. This is greater than timed value because untimed waits spin faster since they don't need to check times on each spin.
    • spinForTimeoutThreshold

      private static final long spinForTimeoutThreshold
      The number of nanoseconds for which it is faster to spin rather than to use timed park. A rough estimate suffices.
      See Also:
    • tail

      tail of the queue
    • cleanMe

      Reference to a cancelled node that might not yet have been unlinked from queue because it was the last inserted node when it cancelled.
  • Constructor Details

    • LinkedTransferQueue

      public LinkedTransferQueue()
      Creates an initially empty LinkedTransferQueue.
    • LinkedTransferQueue

      public LinkedTransferQueue(Collection<? extends E> c)
      Creates a LinkedTransferQueue initially containing the elements of the given collection, added in traversal order of the collection's iterator.
      Parameters:
      c - the collection of elements to initially contain
      Throws:
      NullPointerException - if the specified collection or any of its elements are null
  • Method Details