单例:
class singleton{
private singleton(){} //private 的构造方法
private Singleton instance;
public static singleton getInstance(){
if(instance == null){
init()
}
return instance;
}
private static synchronized void init(){ //初始化的方法用synchronized,并与get方法分开。
if(instance == null){
instance = new Singleton();
}
}