DefaultSingletonBeanRegistry.java 三级缓存
public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements SingletonBeanRegistry {/** Cache of singleton objects: bean name to bean instance. 一级缓存 */private final Map<String, Object> singletonObjects = new ConcurrentHashMap<>(256);/** Cache of singleton factories: bean name to ObjectFactory. 三级缓存 */private final Map<String, ObjectFactory<?>> singletonFactories = new HashMap<>(16);/** Cache of early singleton objects: bean name to bean instance. 二级缓存 */private final Map<String, Object> earlySingletonObjects = new ConcurrentHashMap<>(16);.../*** Return the (raw) singleton object registered under the given name.* <p>Checks already instantiated singletons and also allows for an early* reference to a currently created singleton (resolving a circular reference).* @param beanName the name of the bean to look for* @param allowEarlyReference whether early references should be created or not* @return the registered singleton object, or {@code null} if none found*/@Nullableprotected Object getSingleton(String beanName, boolean allowEarlyReference) {// Quick check for existing instance without full singleton lockObject singletonObject = this.singletonObjects.get(beanName);if (singletonObject == null && isSingletonCurrentlyInCreation(beanName)) {singletonObject = this.earlySingletonObjects.get(beanName);if (singletonObject == null && allowEarlyReference) {synchronized (this.singletonObjects) {// Consistent creation of early reference within full singleton locksingletonObject = this.singletonObjects.get(beanName);if (singletonObject == null) {singletonObject = this.earlySingletonObjects.get(beanName);if (singletonObject == null) {ObjectFactory<?> singletonFactory = this.singletonFactories.get(beanName);if (singletonFactory != null) {singletonObject = singletonFactory.getObject();this.earlySingletonObjects.put(beanName, singletonObject);this.singletonFactories.remove(beanName);}}}}}}return singletonObject;}}
原文作者:小丸子的呆地
原文链接:
https://www.jianshu.com/p/d17795a605de
推荐阅读
- 红茶对胃酸,云顶红茶图片
- 红茶蜂蜜养胃,蜂蜜红茶胃
- AMD|32核Zen 4加持!AMD新一代EPYC处理器现身:缓存翻番
- 红茶枸杞水,红茶能配枸杞和冰糖吗
- 别再自己瞎写工具类了,SpringBoot 内置工具类应有尽有,建议收藏
- 红茶二级三级区别,甘露和绿茶区别
- 春季喝红茶好吗,消化性溃疡喝黑茶好吗
- 发烧喝红茶,发烧了能喝红茶吗
- 红茶特级和特三级,滇江红茶多少钱
- 安溪三级红茶价格,滇江红茶多少钱