单例模式

class Singleton{
    private Singleton(){

    }
    private static volatile Singleton singleton = null;
    public static Singleton getInstance(){
        if (singleton == null){
            synchronized (Singleton.class){
                if (singleton == null){
                    singleton = new Singleton();
                }
            }
        }
        return singleton;
    }

}

 

posted @ 2023-03-03 15:04  诸葛卧龙仙人  阅读(13)  评论(0)    收藏  举报