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

Two threads run computeIfAbsent on the SAME key of a ConcurrentHashMap at nearly the same time. Which statement is guaranteed?

ConcurrentHashMap<String,Integer> map = new ConcurrentHashMap<>(); // Thread A and Thread B both run: map.computeIfAbsent("k", key -> expensiveCompute());