public class Singleton6 {
private volatile static Singleton6 instance;
private Singleton6(){
}
public static Singleton6 getInstance() {
if (instance == null) {
synchronized (Singleton6.class){
if(instance == null){
instance = new Singleton6();
}
}
}
return instance;
}
}
synchronized 加在方法上就没有重排序的问题了吗,synchronized 不是可以防止重排序的吗?