1Z0-829 Double-checked locking Practice Question
Exhibit
public class Singleton {
private static volatile Singleton instance;
private Singleton() {}
public static Singleton getInstance() {
if (instance == null) {
synchronized (Singleton.class) {
if (instance == null) {
instance = new Singleton();
}
}
}
return instance;
}
}Refer to the exhibit. Which statement about this Singleton implementation is correct?
⚠ Common exam trap
Oracle often tests the misconception that volatile is unnecessary in double-checked locking. Without volatile, instruction reordering can expose a partially constructed object, even with synchronized blocks.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
It may still have a race condition due to instruction reordering.
The provided Singleton implementation uses double-checked locking without declaring the instance variable as volatile. Without volatile, the JVM may reorder instructions such that a thread reads a non-null reference to a partially constructed object, leading to a race condition. This is a classic pitfall in Java concurrency.
Go deeper
Related to this question
About these practice questions
This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.