单例模式

/**
* 单例模式:懒汉式
*/
class Singleton{
private static volatile Singleton singleton = null;
private Singleton(){

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

posted @ 2019-05-13 12:05  keepup~  阅读(116)  评论(0编辑  收藏  举报