ConcurrentHashMap documentation says:
Retrieval operations (including get) generally do not block, so may overlap with update operations (including put and remove). Retrievals reflect the results of the most recently completed update operations holding upon their onset. (More formally, an update operation for a given key bears a happens-before relation with any (non-null) retrieval for that key reporting the updated value.)
But I am not able to understand how retrieval operation do not block with update/remove operation for same key ?
"an update operation for a given key bears a happens-before relation with any (non-null) retrieval for that key"
that sort of indicate that concurrent hash map has some way create sequence for read/update/remove operations on same key. But that mean read operations are blocked by update/remove operations.
Not sure what I am missing here.
HashMapand applying sychronization or locks (java.util.concurrent.lockspackage) to read and update the collection. Perhaps using aConcurrentHashMap, instead of aHashMapand sychronization, in such case may be a simpler way.