package com.bila.singleton;
/**
* @Author: Magician
* @Desc:
* 单例模式03 - 懒汉模式 - DCL:双重校验
* 基于Singleton02,减小锁的粒度,将synchronized锁代码块
*
* 注意:必须进行双重校验,不然存在线程安全问题
*
* 比较完美的写法
*
* @Date: 2020/06/28
* @Modify By:
*/
public class Singleton03 {
private static Singleton03 instance ;
private Singleton03() {}
public static Singleton03 getInstance() {
if (instance == null) {
synchronized (Singleton03.class) {
if (instance == null) {
instance = new Singleton03();
}
}
}
return instance;
}
}