多线程-单例设计模式懒汉 饿汉

来源:互联网 发布:2017年网络关键词 编辑:程序博客网 时间:2024/06/02 05:29
饿汉 class Single{    private static final Single s = new  Single();    private Single();    private static Single getInstance(){           return a;    }}懒汉class Single{   private static Single s= null;   private Single(){}   public static Single getInstance){     if(s == null){       synchronized (Single.class){            if(s == null){                s = new Single();            }       }     }       return s;   }}


0 0