CHM (ConcurrentHashMap), instead of synchronizing each method with a common lock, restricting access to one thread at a time, it uses a finer-grained locking mechanism called locking to provide a greater degree of sharing. Arbitrarily many reading streams can simultaneously access the map, readers can access the map at the same time as writers, and a limited number of authors can simultaneously change the map. The result is much higher throughput with parallel access, with single-threaded access. ConcurrentHashMap, along with other concurrent collections, synchronized collection classes by providing iterators that do not throw a ConcurrentModificationException, which eliminates the need to lock the collection during iteration.
As with all improvements, there are still a few tradeoffs. The semantics of the methods that work on the entire Map, such as size and isEmpty, were slightly weakened to reflect the parallel nature of the collection. Since the size result may be outdated at the time of its calculation, this is really only an estimate, so the size is allowed to return an approximation instead of an exact calculation. Although this may seem alarming at first, in reality methods such as size and isEmpty are much less useful in parallel environments because these quantities drive the targets.
Secondly, Collections.synchronizedMap
It's just a simple HashMap with synchronized methods - I would call it an obsolete dute in CHM
dantuch
source share