单例模式:确保一个类最多只有一个实例,并提供一个全局访问点(线程池、缓存等)
public class Singleton {
private static Singleton instance = null;
private Singleton() {
}
public static Singleton getInstance() {
if(instance == null) {
syn();
}
return instance;
}
private static synchronized void syn() {
if(instance == null) {
instance = new Singleton();
}
}
}