单例模式 (二) 延迟加载/"懒汉模式" —— 使用DCL双检查锁机制

来源:互联网 发布:数据库系统的二级映射 编辑:程序博客网 时间:2024/05/21 07:52
package com.multithreading;/** * Created by nanzhou on 2017/6/30. */public class Singleton {    private volatile static Singleton singleton;    private Singleton() {    }    public static Singleton getIntance() {        if (null == singleton) {            synchronized (Singleton.class) {                if (null == singleton) {                    singleton =  new Singleton();                }            }        }            return singleton;        }    }

阅读全文
1 0