懒汉式单例模式之双重检查机制---Java实现
package org.study.singleton;
public class DoubleCheckSingleton {
private DoubleCheckSingleton(){};
private static volatile DoubleCheckSingleton instance = null;
public static DoubleCheckSingleton getInstance() {
if (instance == null) {
synchronized (DoubleCheckSingleton.class) {
if (instance == null) {
instance = new DoubleCheckSingleton();
}
}
}
return instance;
}
}
程序改变世界