singletonsCurrentlyInDestruction
singletonObject
一级缓存 bean name —> bean instance
earlySingletonObjects
二级缓存 bean name —> bean instance
早期的bean
earlyProxyReferences
标记是否创建过代理的bean
singletonFactories
三级缓存 bean name —> ObjectFactory
缓存工厂bean
refresh()
getSingleton()
protected Object getSingleton(String beanName, boolean allowEarlyReference) {//从一级缓存区里面取Object singletonObject = this.singletonObjects.get(beanName);//一级缓存为空并且被标记为已创建if (singletonObject == null && isSingletonCurrentlyInCreation(beanName)) {synchronized (this.singletonObjects) {//从二级缓存里面取singletonObject = this.earlySingletonObjects.get(beanName);if (singletonObject == null && allowEarlyReference) {//二级缓存也没有到三级缓存里面取ObjectFactory<?> singletonFactory = this.singletonFactories.get(beanName);if (singletonFactory != null) {//三级缓存里面取到了再放入二级缓存里面去singletonObject = singletonFactory.getObject();this.earlySingletonObjects.put(beanName, singletonObject);this.singletonFactories.remove(beanName);}}}}return singletonObject;}
