手写单例模式
1. 懒汉式(双重检查加锁版本)
public class Singleton {
private volatile static Singleton uniqueInstance;
private Singleton() {}
public static Singleton getInstance(){
if (uniqueInstance == null) {
synchronized(sSingleton.class) {
if (uniqueInstance == null) {
uniqueInstance = new Singleton();
}
}
}
return uniqueInstance;
}
}