...
ConcurrentHashMap
, along with the other concurrent collections, further improve on the synchronized collection classes by providing iterators that do not throwConcurrentModificationException
, as a result eliminating the need to lock the collection during iteration. The iterators returned byConcurrentHashMap
are weakly consistent instead of fail-fast. A weakly consistent iterator can tolerate concurrent modification, traverses elements as they existed when the iterator was constructed, and may (but is not guaranteed to) reflect modifications to the collection after the construction of the iterator.
Note that methods such as size()
and isEmpty()
are allowed to return an approximate result for performance reasons. Code should not rely on these return values for deriving exact results.
Risk Assessment
Non-atomic code can induce race conditions and affect program correctness.
...