单例模式:产生单一的对象
public class Singleton {
private static Singleton uniqueInstance;
private Singleton(){
}
public synchronized static Singleton getInstance(){
if(uniqueInstance==null){
uniqueInstance=new Singleton();
}
returnuniqueInstance;
}
}//加synchronized关键字是为了多线程并发执行时也能保证只创建单个实例