OOP & Design Patterns - Singleton Pattern - Thread Safety, Double-Checked Locking & Lazy Init
Examine the following Java-like Singleton implementation using double-checked locking:
class Singleton {
private static Singleton instance;
public static Singleton getInstance() {
if (instance == null) {
synchronized(Singleton.class) {
if (instance == null) {
instance = new Singleton();
}
}
}
return instance;
}
}
What is the primary issue with this implementation?