public class LazySafeSingleton {
private static LazySafeSingleton lazySafeSingleton;
private LazySafeSingleton() {
}
// synchronized keyword in the getLazySafeSingleton() method. This is needed to prevent race conditions in multi-threaded environments.
public static synchronized LazySafeSingleton getLazySafeSingleton() {
if (lazySafeSingleton == null) {
lazySafeSingleton = new LazySafeSingleton();
}
return lazySafeSingleton;
}
public void hello() {
System.out.println("hello ?");
}
}
class SafeSingletonTest {