码迷,mamicode.com
首页 > 其他好文 > 详细

实现Singleton模式

时间:2014-07-10 16:24:37      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   div   new   设计   

设计一个类,我们只能生成该类的一个实例。

 

单线程可用,多线程不安全:

public class Singleton {
    private static Singleton instance = null;

    private Singleton() {

    }

    public static Singleton getInstance() {
        if (instance == null)
            instance = new Singleton();
        return instance;

    }

}

 

 

实现Singleton模式,布布扣,bubuko.com

实现Singleton模式

标签:style   blog   color   div   new   设计   

原文地址:http://www.cnblogs.com/jdflyfly/p/3834897.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!