Java 单列模式

 

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

 

posted @ 2018-03-14 14:42  Code_Java  阅读(66)  评论(0)    收藏  举报