Code Room
Code reviewHard
Question
Review this Java lazy-singleton initialization.
Is this double-checked locking correct? If not, what is the precise failure?
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
public final class ConfigCache { private static ConfigCache instance; // not volatile private final Map<String, String> settings; private ConfigCache() { settings = loadFromDisk(); // populates the map } public static ConfigCache get() { if (instance == null) { // first check (no lock) synchronized (ConfigCache.class) { if (instance == null) { // second check instance = new ConfigCache(); // (1) } } } return instance; }}Run or narrate your approach, then ask the coach.