Spring4.3版本的DefaultListableBeanFactory.registerBeanDefinition,为什么这样写?top和bottom有什么区别

Spring4.3版本的DefaultListableBeanFactory.registerBeanDefinition,为什么这样写?top和bottom有什么区别

如果是多线程的,beanDefinitionNames被覆盖怎么办?将会丢失一些beanName

if (hasBeanCreationStarted()) {
            // Cannot modify startup-time collection elements anymore (for stable iteration)
            synchronized (this.beanDefinitionmap) {
                this.beanDefinitionmap.put(beanName,beanDefinition);
                List<String> updatedDefinitions = new ArrayList<>(this.beanDefinitionNames.size() + 1);
                updatedDefinitions.addAll(this.beanDefinitionNames);
                updatedDefinitions.add(beanName);
                this.beanDefinitionNames = updatedDefinitions;
                if (this.manualSingletonNames.contains(beanName)) {
                    Set<String> updatedSingletons = new LinkedHashSet<>(this.manualSingletonNames);
                    updatedSingletons.remove(beanName);
                    this.manualSingletonNames = updatedSingletons;
                }
            }
        }
        else {
            // Still in startup registration phase
            this.beanDefinitionmap.put(beanName,beanDefinition);
            this.beanDefinitionNames.add(beanName);
            this.manualSingletonNames.remove(beanName);
        }
qyrwj 回答:Spring4.3版本的DefaultListableBeanFactory.registerBeanDefinition,为什么这样写?top和bottom有什么区别

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3096481.html

大家都在问