/**
* mail 190042477@qq.com
* description: 单例 Dcl
*/
public class LazySingleton {
private static volatile LazySingleton lazySingleton = null;
private LazySingleton() {
}
public static LazySingleton getInstance() {
if (lazySingleton == null) {
synchronized (LazySingleton.class) {
if (lazySingleton == null) {
lazySingleton = new LazySingleton();
}
}
}
return lazySingleton;
}
}
不足之处:JVM的即使编译器中存在指令重排序的优化
优化:静态内部类 枚举