`public class Singleton4 {
private static final AtomicReference<Singleton4> INSTANCE = new AtomicReference<Singleton4>();
public static Singleton4 getInstance() {
for (;;) {
Singleton4 current = INSTANCE.get();
if (current != null) {
return current;
}
current = new Singleton4();
if (INSTANCE.compareAndSet(null, current)) {
return current;
}
}
}
}
`