本帖最后由 寻找人生目标 于 2014-6-17 16:19 编辑
静态内部类 优点: 加载是不会初始化静态变量INSTANCE,因为没有主动使用
- class InternalSingleton{
- private static class SingletonHolder{
- private final static InternalSingleton INSTANCE=new InternalSingleton();
- }
- private InternalSingleton(){}
- public static InternalSingleton getInstance(){
- return SingletonHolder.INSTANCE;
- }
- }
复制代码
双重校验锁据说什么当前内存模式不能用 搞不懂 双检查锁只有在 jdk 1.5 及以上版本才能达到单例的效果的
|