public class LazyDoubleCheckSingleton {
private volatile static LazyDoubleCheckSingleton lazyDoubleCheckSingleton = null;
private LazyDoubleCheckSingleton(){}
private int i=0;
public static LazyDoubleCheckSingleton getInstance(){
if (lazyDoubleCheckSingleton==null){
synchronized (LazyDoubleCheckSingleton.class){
if(lazyDoubleCheckSingleton==null){
lazyDoubleCheckSingleton = new LazyDoubleCheckSingleton();
}
}
}
return lazyDoubleCheckSingleton;
}
public void inc(){
++i;
System.out.println("**********i="+i);
}
}
懒汉加载双重检查单例模式
最新推荐文章于 2023-12-01 22:23:54 发布