Module java.base

Class ConcurrentSkipListSet<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
java.util.concurrent.ConcurrentSkipListSet<E>
Type Parameters:
E - the type of elements maintained by this set
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, NavigableSet<E>, Set<E>, SortedSet<E>

public class ConcurrentSkipListSet<E> extends AbstractSet<E> implements NavigableSet<E>, Cloneable, Serializable
A scalable concurrent NavigableSet implementation based on a ConcurrentSkipListMap. The elements of the set are kept sorted according to their natural ordering, or by a Comparator provided at set creation time, depending on which constructor is used.

This implementation provides expected average log(n) time cost for the contains, add, and remove operations and their variants. Insertion, removal, and access operations safely execute concurrently by multiple threads.

Iterators and spliterators are weakly consistent.

Ascending ordered views and their iterators are faster than descending ones.

Beware that, unlike in most collections, the size method is not a constant-time operation. Because of the asynchronous nature of these sets, determining the current number of elements requires a traversal of the elements, and so may report inaccurate results if this collection is modified during traversal.

Bulk operations that add, remove, or examine multiple elements, such as AbstractCollection.addAll(java.util.Collection<? extends E>), Collection.removeIf(java.util.function.Predicate<? super E>) or Iterable.forEach(java.util.function.Consumer<? super T>), are not guaranteed to be performed atomically. For example, a forEach traversal concurrent with an addAll operation might observe only some of the added elements.

This class and its iterators implement all of the optional methods of the Set and Iterator interfaces. Like most other concurrent collection implementations, this class does not permit the use of null elements, because null arguments and return values cannot be reliably distinguished from the absence of elements.

This class is a member of the Java Collections Framework.

Since:
1.6
Author:
Doug Lea
See Also:
  • Constructor Details

    • ConcurrentSkipListSet

      public ConcurrentSkipListSet()
      Constructs a new, empty set that orders its elements according to their natural ordering.
    • ConcurrentSkipListSet

      public ConcurrentSkipListSet(Comparator<? super E> comparator)
      Constructs a new, empty set that orders its elements according to the specified comparator.
      Parameters:
      comparator - the comparator that will be used to order this set. If null, the natural ordering of the elements will be used.
    • ConcurrentSkipListSet

      public ConcurrentSkipListSet(Collection<? extends E> c)
      Constructs a new set containing the elements in the specified collection, that orders its elements according to their natural ordering.
      Parameters:
      c - The elements that will comprise the new set
      Throws:
      ClassCastException - if the elements in c are not Comparable, or are not mutually comparable
      NullPointerException - if the specified collection or any of its elements are null
    • ConcurrentSkipListSet

      public ConcurrentSkipListSet(SortedSet<E> s)
      Constructs a new set containing the same elements and using the same ordering as the specified sorted set.
      Parameters:
      s - sorted set whose elements will comprise the new set
      Throws:
      NullPointerException - if the specified sorted set or any of its elements are null
  • Method Details