advancedMultithreading & Concurrency330 of 436

Double-checked locking singleton without volatile: what can a second thread see?

Tests whether you know a second thread can see a partially-constructed object -- without volatile, the JIT/JVM can reorder the reference assignment ahead of the constructor finishing, so the null-check passes but the fields aren't initialized yet.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

← Back to all Core Java questions