为什么易失性在双重检查锁定中使用?
public class Singleton {
private volatile static Singleton instance;
private Singleton() {}
public static Singleton getInstance() {
if (instance == null) {
synchronized (Singleton.class) {
if (instance == null) {
instance = new Singleton();
}
}
}
return instance;
}}volatilevolatile
冉冉说
慕容3067478
随时随地看视频慕课网APP