Java set of thread-safe

CopyOnWriteArraySetConcurrentSkipListSet

 

Correspondence between the thread-safe collection classes

  • HashSet -> CopyOnWriteArraySet
  • TreeSet -> ConcurrentSkipListSet

CopyOnWriteArraySet Overview

  • A CopyOnWriteArrayList depends on the underlying implementation, and therefore suitable for small amount of data, the read operation is greater than the set write operation;
  • Iterator does not support variable remove operation, when using fast iterates over;

ConcurrentSkipListSet Overview

  • And TreeSet as support natural order, the comparator can be defined at construction time;
  • Which contains, add, remove operations are thread-safe, but for batch operations, such as addAll removeAll, containsAll does not guarantee atomic execution, because the underlying or call contains, add, remove method, when a batch operation, only add each other to ensure that operations are atomic, the call for batch operations, or to manually add a lock to ensure atomicity;
  • Storage is not empty element;


Author: Urumqi No. 001 programmer
link: https: //www.jianshu.com/p/2bc70f6e838e
Source: Jane books
are copyrighted by the author. Commercial reprint please contact the author authorized, non-commercial reprint please indicate the source.

 

Guess you like

Origin www.cnblogs.com/anenyang/p/12330505.html
Recommended