Advanced
Java
Q81 / 100
What problem does the double-checked locking pattern solve, and what Java feature makes it correct?
Correct! Well done.
Incorrect.
The correct answer is B) Reduces lock contention for lazy singleton initialization; requires volatile on the instance field
B
Correct Answer
Reduces lock contention for lazy singleton initialization; requires volatile on the instance field
Explanation
Without volatile, the JIT can reorder writes so another thread sees a partially constructed object. volatile establishes a happens-before, making DCL safe.
Progress
81/100