设计模式之单例模式

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

不延迟初始化

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

你可能感兴趣的:(设计模式)