Java · Hard · Pro
Double-checked locking — why broken pre-Java 5, fix with volatile?
JavaConcurrencySeniorTricky
Double-checked locking
DCL lazy-init tested instance field twice—once unsynchronized for speed, once inside lock. Pre-Java 5, without volatile, another thread could see a partially constructed singleton.
- Fix: declare singleton reference
volatile.