Class SparseConcurrentList<E>

java.lang.Object
java.util.concurrent.CopyOnWriteArrayList<E>
com.linkedin.venice.utils.SparseConcurrentList<E>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess
Direct Known Subclasses:
SparseConcurrentListWithOffset

public class SparseConcurrentList<E> extends CopyOnWriteArrayList<E>
A List implementation with some usability improvements around resizing. In particular, the list provides Map semantics in some cases where the regular List behavior would be to throw ArrayIndexOutOfBoundsException. Note on concurrency and performance characteristics: This class extends CopyOnWriteArrayList and thus mimics its general characteristics: it is threadsafe, very efficient for read operations, but it incurs a locking overhead on mutation operations. Unfortunately, the locking overhead may be up to double that of the parent class, because we cannot get access to CopyOnWriteArrayList.lock since it is package private and Java doesn't allow us to define new classes in the java.* package. So instead we are making every mutation operation synchronized. The end result should be that the inner lock inside the parent class never has any contention, since the locking is effectively external. In any case, even if this double-locking has any overhead, it should not be a big concern, since the read operations are still lock-free, and (at the time of this writing), only the read operations are used on the hot path.
See Also: