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

单例模式

时间:2017-07-27 12:44:56      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:null   test   new   public   构造函数   .class   zed   变量   instance   

public class SingleTest{

  //私有构造函数

  private SingleTest(){}

  //volatile变量

  private static Volatile SingleTest instance;

       //静态方法

  public static SingleTest getInstance(){

    if(null==instance){

      synchronized (SingleTest.class){

        if(instance == null){

          instance = new SingleTest();

        }

      }

              }

    return instance;

       }

}

单例模式

标签:null   test   new   public   构造函数   .class   zed   变量   instance   

原文地址:http://www.cnblogs.com/ajfajz/p/7244088.html

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