Java / Concurrent collections
How ConcurrentHashMap works internally?
ConcurrentHashMap works similar to HashMap by storing key/value pairs and retrieving values. The difference in its implementation in terms of concurrency and how it achieves thread-safety. ConcurrentHashMap divides the map into several segments, by default 16, also known as synchronization level.
Due to the segment level synchronization, get(), put(), contains() operation can be performed concurrently as it never locks the whole map but only the relevant segment gets locked. Multiple readers can access the map concurrency with writers and a limited number of writers can modify the map concurrently. The result is better throughput and Scalability.
ConcurrentHashMap is a mini hash table with a bucket and linked list of hash entries in case of collision.
More Related questions...