顺便说一句,想出此方法的不是人,是神!顶礼膜拜!
public class Test {
private static class SingletonHolder {
private static Singleton instance = new Singleton();
}
private Test() {
}
public static Singleton getInstance() {
return SingletonHolder.instance;
}
}
本文介绍了一种使用静态内部类实现单例模式的方法,该方法既保证了线程安全,又避免了同步带来的性能影响。通过这种方式,单例实例仅在首次请求时创建。

被折叠的 条评论
为什么被折叠?



