public class Singleton {
private volatile static Singleton instance = null;
private Singleton() {
}
/**
* @return
*/
public static Singleton getInstance() {
if (instance == null) {
synchronized (Singleton.class) {
if (instance == null) {
instance=new Singleton();
}
}
}
return instance;
}
}
这段代码如果instance不加volatile可不可能存在instance=new Singleton();后instance
对其他线程暂时不可见的现象