Java Core & JVM (50 Qs)•Part 3: JVM Internals, Low-Latency Systems & Production Tuning (25 - 35)
`ConcurrentHashMap` Concurrency Architecture.
senior LevelSystem Design
In Simple Words:
HashtableandCollections.synchronizedMaplock the entire table with a single synchronized lock, killing throughput.ConcurrentHashMap:- In Java 7: Used 16 independent lock segments (Lock Striping).
- In Java 8+: Uses lock-free CAS (Compare-And-Swap) for inserting the first node in empty bucket bins, and synchronized locks on individual bucket head nodes for hash collisions. Reads (
get()) are completely lock-free viavolatilenodes!