From the Javadoc I know ConcurrentHashMap.replace is atomic, but what about ConcurrentHashMap.put? I see they are differently implemented in the source code but I’m not able to figure out their differences. Any gurus to give some guidelines about how to use these two methods?
From the Javadoc I know ConcurrentHashMap.replace is atomic, but what about ConcurrentHashMap.put ? I
Share
They are functionally different.
replaceonly stores the key-value pair if there already was a value stored under the specified key. The API documentation ofreplaceexplains it: