user1870400 user1870400 - 6 months ago 21
Java Question

can someone explain the interleaving of two threads such that one of the thread gets null when called putIfAbsent of concurrentHashMap in java?

can someone explain the interleaving of two threads such that one of the thread gets null when two threads call

putIfAbsent
of
ConcurrentHashMap
in Java?

Answer

putIfAbsent returns the previous value associated with the key, or null if there was no such value. So the first thread attempting to put the value in the map will always have null returned to it.

Comments