Each method of ConcurrentHashMap
is thread-safe. But calling multiple methods from ConcurrentHashMap
for the same key leads to race conditions. And calling the same method from ConcurrentHashMap
recursively for different keys leads to deadlocks.
Let us look at an example to see why this happens: