public class Single {
public void show(){
System.out.println("helloworld");
}
private static Single s = null;
private Single(){}
public static synchronized Single getInstance(){
if(s == null){
synchronized(Single.class){
if(s == null){
s = new Single();
}
}
}
return s;
}
}
求教:在锁synchronized中的那个s==null的判断能不能不要嘛?前面在外边已经判断过了一次,进来还需要判断吗?
|
|