ConcurrentHashMap read and write locks

I think javadoc answers both your questions:

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. For aggregate operations such as putAll and
clear, concurrent retrievals may reflect insertion or removal of only
some entries.

Segments are for update operations:

The allowed concurrency among update operations is guided by the
optional concurrencyLevel constructor argument (default 16), which is
used as a hint for internal sizing.

So, in short, reads are not blocked (it is implemented as reading volatile variables). Writes could block each other if they write in the same segment.

Leave a Comment