Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterating over ConcurrentHashMap [closed]

I referred many links regarding Iterator of ConcurrentHashMap, like Is iterating ConcurrentHashMap values thread safe? or any other on Google, even java doc,yet i am not much getting what kind of behavior i might face while iterating the Concurrenthashmap and simultaneously modifying it

like image 424
KCS Avatar asked Jan 09 '14 16:01

KCS


1 Answers

Read the JavaDoc for ConcurrentHashMap.values():

The view's iterator [..] guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction.

If you're interested in the contract of the other iterators, they have documentation as well.

like image 129
Markus Malkusch Avatar answered Sep 28 '22 14:09

Markus Malkusch