懒汉式单例模式之双重检查机制---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;
    }
}


posted @ 2021-03-06 23:11  Leo-Wong  阅读(102)  评论(0编辑  收藏  举报