Thread-safe set

The thread-safe version of a Set is CopyOnWriteArraySet. The following table enumerates the Java built-in single-threaded and multithreaded sets:

Single thread

Multithreaded

HashSet

TreeSet (sorted set)

LinkedHashSet (maintain insertions order)

BitSet

EnumSet

ConcurrentSkipListSet (sorted set)

CopyOnWriteArraySet (often reads, seldom updates)

 

This is a Set that uses an internal CopyOnWriteArrayList for all of its operations. Creating such a Set can be done as follows:

Set<Integer> set = new CopyOnWriteArraySet<>();
Use this collection when reads are frequent and changes are seldom.

The thread-safe version of NavigableSet is ConcurrentSkipListSet (concurrent SortedSet implementation, with most basic operations in O(log n)).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.104.183