京峰LInux运维安全高级架构师班
// 创建单例class SingletonObject {
private static SingletonObject SINGLETON_INSTANCE;
public static SingletonObject getInstance() {
// 创建过程非常昂贵,希望第一次使用的时候才去创建
// check-then-act
// 多线程模式下可能创建多个实例
if (SINGLETON_INSTANCE == null) {
SINGLETON_INSTANCE = new SingletonObject();
}
return SINGLETON_INSTANCE;
}