Class ThreadRobustList<T>

java.lang.Object
com.yahoo.yolean.concurrent.ThreadRobustList<T>
All Implemented Interfaces:
Iterable<T>

@Deprecated(forRemoval=true) public class ThreadRobustList<T> extends Object implements Iterable<T>
Deprecated, for removal: This API element is subject to removal in a future version.
Not used, will be removed in next major release

This class implements a thread-safe, lock-free list of Objects that supports multiple readers and a single writer. Because there are no locks or other memory barriers involved, there exists no happens-before relationship among calls to either methods of the ThreadRobustList. This means that there are no guarantees as to when (or even if) an item add(Object)ed becomes visible through iterator(). If visibility is required, either use explicit synchronization between reader and writer thread, or move to a different concurrent collection (e.g. CopyOnWriteArrayList).

Because it is lock-free, the ThreadRobustList has minimal overhead to both reading and writing. The iterator offered by this class always observes the list in a consistent state, and it never throws a ConcurrentModificationException.

The ThreadRobustList does not permit adding null items.

The usage of ThreadRobustList has no memory consistency effects.

Author:
Steinar Knutsen, bratseth
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
    Constructs a new instance of this class with an initial capacity of 10.
    ThreadRobustList(int initialCapacity)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Constructs a new instance of this class with a given initial capacity.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(T item)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Adds an item to this list.
    boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns whether or not this list is empty.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns an iterator over the items in this list.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • ThreadRobustList

      public ThreadRobustList()
      Deprecated, for removal: This API element is subject to removal in a future version.

      Constructs a new instance of this class with an initial capacity of 10.

    • ThreadRobustList

      public ThreadRobustList(int initialCapacity)
      Deprecated, for removal: This API element is subject to removal in a future version.

      Constructs a new instance of this class with a given initial capacity.

      Parameters:
      initialCapacity - the initial capacity of this list
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Deprecated, for removal: This API element is subject to removal in a future version.

      Returns whether or not this list is empty.

      Returns:
      true if this list has zero items
    • add

      public void add(T item)
      Deprecated, for removal: This API element is subject to removal in a future version.

      Adds an item to this list. As opposed to CopyOnWriteArrayList, items added to this list may become visible to iterators created before a call to this method.

      Parameters:
      item - the item to add
      Throws:
      NullPointerException - if item is null
    • iterator

      public Iterator<T> iterator()
      Deprecated, for removal: This API element is subject to removal in a future version.

      Returns an iterator over the items in this list. As opposed to CopyOnWriteArrayList, this iterator may see items added to the ThreadRobustList even if they occur after a call to this method.

      The returned iterator does not support remove().

      Specified by:
      iterator in interface Iterable<T>
      Returns:
      an iterator over this list