双重检查代码下:
public static Singleton getInstance()
{
if (instance == null)
{
synchronized(Singleton.class) { //1
if (instance == null) //2
instance = new Singleton(); //3
}
}
return instance;
}
为什么不写成这样:
public static Singleton getInstance()
{
synchronized(Singleton.class) { //1
if (instance == null) //2
instance = new Singleton(); //3
}
return instance;
}
求大神赐教?