I was going through the ConcurrentHashMap and this related tutorial, and had some questions.
In the article, it was mention that
ConcurrentHashMapallows multiple readers to read concurrently without any blocking. This is achieved by partitioning the Map into different parts based on concurrency level and locking only a portion of the Map during updates. Default concurrency level is 16, and accordingly the Map is divided into 16 part and each part is governed with a different lock. This means, 16 threads can operate on Map simultaneously, until they are operating on different parts of the Map. This makesConcurrentHashMaphigh performant despite keeping thread-safety intact. Though, it comes with a caveat: Since update operations likeput(),remove(),putAll()orclear()are not synchronized, concurrent retrieval may not reflect the most recent change on the MapAnother point also mentioned in the article: Another important point to remember is iteration over CHM, Iterator returned by
keySetare weakly consistent and they only reflect state ofConcurrentHashMapat a certain point and may not reflect any recent change.
I have not understood the points highlighted in bold, could you provide more info or show me in a simple program?