首页 > 其他 > 详细

一个简单的单例模式Demo

时间:2021-05-30 15:49:21      阅读:17      评论:0      收藏:0      [点我收藏+]
/**
 * @author :nx014924
 * @date :Created in 5/30/2021 1:09 PM
 * @description:
 * @modified By:
 * @version:
 */
public class Singleton {
    private static Singleton singleton;

    //双检锁实现懒汉式单例模式
    public static Singleton getSingleton(){
        if (singleton == null){
            synchronized (Singleton.class){
                if (singleton == null)
                    singleton = new Singleton();
            }
        }
        return singleton;
    }
}

 

一个简单的单例模式Demo

原文:https://www.cnblogs.com/leonandyou/p/14827842.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!