When designing a Singleton class, is it required to use double checking? Why can't I just put an if
condition as well in the synchronize
block? Or is there any break of it?
public static Singleton getInstance() {
synchronized(Singleton.class) {
if (singleton == null) {
singleton = new Singleton();
}
}
return singleton;
}