欢迎光临散文网 会员登陆 & 注册

马老师Java高级互联网架构p5p6p7p8

2022-10-15 15:28 作者:666好听的名字  | 我要投稿

   private static World SINGLETON_WORLD;    public static World getInstance() {        if (SINGLETON_WORLD == null) {            // 问题:多线程的情况下可能会同时进入            SINGLETON_WORLD = new World();        }        return SINGLETON_WORLD;    }    // 双锁检测,在工作中上述两种情况就能够满足了    public static World getInstance() {        if (SINGLETON_WORLD == null) {            synchronized (World.class) {                if (SINGLETON_WORLD == null) {                    SINGLETON_WORLD = new World();                }            }        }      

马老师Java高级互联网架构p5p6p7p8的评论 (共 条)

分享到微博请遵守国家法律