首页 > 其他 > 详细

单例模式

时间:2017-07-27 12:28:11      阅读:259      评论:0      收藏:0      [点我收藏+]

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;

       }

}

单例模式

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

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