单例
public class Singleton {
private Singleton(){}
public static Singleton getInstance(){
return SingletoHolder.singleton;
}
private static class SingletoHolder{
private static final Singleton singleton = new Singleton();
}
}
常规懒汉式会有双重检查锁定失效问题,推荐使用上述代码 静态内部类单例模式实现单例