Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumJavaConcurrentHashMapSingle-choice MCQ

Why is calling computeIfAbsent on a ConcurrentHashMap with a mapping function that itself updates the SAME map a documented hazard?

ConcurrentHashMap<Integer,Integer> m = new ConcurrentHashMap<>(); m.computeIfAbsent(1, k -> { m.computeIfAbsent(2, k2 -> 42); // updates same map inside the function return k * 10; });