Relative Content

Tag Archive for javaconcurrencyconcurrenthashmap

Does Java 11 Properties class uses double synchronization? It uses ConcurrentHashMap and at the same time synchronized methods

I’m currently diving in the implementation of java 11 Properties class. In java 11 source code, Properties class stores its data in a ConcurrentHashMap field called ‘map’. When you call the method setProperty of Properties, under the hood it makes a put method call of its internal ConcurrentHashMap. I understand that ConcurrentHashMap is a thread-safe collection, so i don’t really get why the setProperty method has to be synchronized if ConcurrentHashMap already is. The synchronization of setProperty method isn’t killing the point of using a ConcurrentHashMap. By this i mean that users of Properties class will have to wait to lock for setProperty method that already uses a concurrent collection with its own synchronization.