HashMap Internals & Locks

KOTLIN › Concurrency

HashMap internals, why it breaks under threads, choosing the right map, memory visibility, and locks.

The classic live-coding trap is a thread-safe cache: interviewers check you know how HashMap works inside (buckets, hashCode/equals, resize), what exactly goes wrong when threads share one, and how to fix it with ConcurrentHashMap (which has its own deep-dive topic), atomics or a lock. The follow-ups are about the WHY: visibility, happens-before, and check-then-act races. Candidates fail this area on thread memory sync more than on syntax, so be ready to explain what volatile does and does not guarantee.

What this covers

Study this topic

Further reading