ConcurrentHashMap

KOTLIN › Concurrency

ConcurrentHashMap in depth: lock-free reads, CAS + bin locks, atomic compound ops, and its traps.

ConcurrentHashMap is the JMM's machinery packaged as a map: reads never lock, writes synchronise per bin, and putting a value happens-before retrieving it. Interviewers use it two ways: can you explain HOW it achieves thread safety without a global lock, and do you know its contract well enough to avoid the traps: check-then-act on a 'thread-safe' map, side effects inside compute functions, and trusting size() or iterators to be exact under concurrency. It is the default answer for shared caches in a live-coding round, so know why, and know what it still does not solve.

What this covers

Study this topic

Further reading