How is ConcurrentHashMap better than synchronized HashMap
Another popular interview question. Sometimes this multithreading + collection interview question is also asked as, the difference between ConcurrentHashMap and Hashtable in Java. The problem with synchronized HashMap or Hashtable was that whole Map is locked when a thread performs any operation with Map.
The java.util.ConcurrentHashMap class solves this problem by using lock stripping technique, where the whole map is locked at different segments and only a particular segment is locked during the write operation, not the whole map. The ConcurrentHashMap also achieves it’s scalability by allowing lock-free reads as read is a thread-safe operation.