put() inherited from the AbstractMap class, which ConcurrentHashMap continues. The specific concurrency contract is not specified by put() . This inheritance allows the use of ConcurrentHashMap in the "traditional" Map context. But the AbstractMap method is not atomic.
replace() is implemented at the request of the ConcurrentMap interface. This interface requires atomic operations such as replace() . Only the methods of this interface should be used in code with simultaneous use.
To have the atomic put() operation, use putIfAbsent() coming from the same ConcurrentMap interface.
source share