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?
From the javadoc of putIfAbsent
:
returns:
the previous value associated with the specified key, or null if there was no mapping for the key.
So the first thread attempting to put the value in the map will always have null
returned to it.