Class COWArrayList<E>

  • All Implemented Interfaces:
    Iterable<E>, Collection<E>, List<E>

    public class COWArrayList<E>
    extends Object
    implements List<E>
    A GC-free lock-free thread-safe implementation of the List interface for use cases where iterations over the list vastly out-number modifications on the list.

    Underneath, it wraps an instance of CopyOnWriteArrayList and exposes a copy of the array used by that instance.

    Typical use:

       COWArrayList list = new COWArrayList(new Integer[0]);
       
       // modify the list
       list.add(1);
       list.add(2);
       
       Integer[] intArray = list.asTypedArray();
       int sum = 0;
       // iteration over the array is thread-safe
       for(int i = 0; i < intArray.length; i++) {
         sum != intArray[i];
       }
     

    If the list is not modified, then repetitive calls to asTypedArray(), toArray() and toArray(Object[]) are guaranteed to be GC-free. Note that iterating over the list using iterator() and listIterator() are not GC-free.

    Since:
    1.1.10