Member-only story
Java Concurrent HashMap Concepts
Hashmap Evolution over the years.
Concurrent HashMap is a Hash based map like HashMap but it uses entirely a different locking strategy that offer better concurrency and scalability.
Instead of synchronizing every method on a common lock ,restricting access to a single thread at a time , its uses fine grained locking mechanism that is called lock stripping to allow a greater degree of shared access.
Arbitrarily many reading threads can access the map concurrently , readers can access the map concurrently with writers and a limited number of writers can modify the map concurrently.
ConcurrentHashMap provides iterator that does not throw ConcurrentModificationException that means we don’t need to lock the collection while iterating over it.
The iterator returned by ConcurrentHashMap are weakly consistent instead of being fail-fast that means the weakly consistent iterator does not reflect modifications to the collection after the construction of the iterator.
Java 8 Specific Improvements :
- Java 8 brought about important changes in the way
ConcurrentHashMap. - The map was restructured to use red black trees after the certain size increase( which is 8)
HashMap, but with…