首页 > 编程语言 > 详细

java简单单例设计模式-饿汉式||无线程锁懒汉

时间:2020-03-25 17:10:05      阅读:42      评论:0      收藏:0      [点我收藏+]

 

/***

*饿汉式|

/********

class Singleton{
    public static Singleton s = new Singleton();
    private Singleton(){}
    public static Singleton getInstance(){
      return s;
   }

}

/***

*懒汉式|

/********

class Singleton2{

    private static  Singleton2 s;
    private Singleton2(){}
    public static  Singleton2 getInstance(){
       if( s == null){
            s = new Singleton2();
        }
        return s;
    }
}

 

java简单单例设计模式-饿汉式||无线程锁懒汉

原文:https://www.cnblogs.com/bigdatayun/p/12567224.html

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