“This is the 31st day of my participation in the August Gwen Challenge.

1. Do you know spring’s internal level 3 cache?

The answer is: DefaultSingletonBeanRegistry

package org.springframework.beans.factory.support;

public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements SingletonBeanRegistry { protected static final Object NULL_OBJECT = new Object(); protected final Log logger = LogFactory.getLog(this.getClass()); private final Map<String, Object> singletonObjects = new ConcurrentHashMap(256); Private final Map<String, ObjectFactory<? >> singletonFactories = new HashMap(16); Private Final Map<String, Object> earlySingletonObjects = new HashMap(16); // Secondary semi-finished productCopy the code

Only three levels of key-value where value is the creation bean of the factory bean

Conclusion: The singleton is slow

Understanding: Because the objects we first created were singleton-based, all singletons went through their full life cycle — into the cache — before they could begin to resolve circular dependencies

Because photoTypes are recreated one object at a time, they cannot be put into the cache, and thus cannot be used with a three-level cache to resolve circular dependencies

2. Composition of the three-level cache: three maps plus four methods;

Public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements SingletonBeanRegistry {/ * level 1 cache. Bean singleton, a collection of concurrentHashMap secure; 1. Cache of singleton objects, singleton pool, 2. Representation of objects that have gone through a full life cycle -- a place to put the finished product 3. */ Private Final Map<String, Object> singletonObjects = new ConcurrentHashMap(256); /* Early singleton, bean object instantiated, but not initialized - properties not populated 1. 2. The object in the bean is also singleton, */ Private Final Map<String, Object> earlySingletonObjects = new HashMap(16); /* singletonFactories,value is objectFactory----> Bean factory has no singleton object, there is spring container, but singleton object does not exist, so we start to create bean, Then doCreateBean (1). Get the singleton object getSingleton(), and if not, create object 2 for the bean. Instantiate bean object, doCreateBean(); 3. Initialize the bean object, populateBean(); AddSingleton (); */ private final Map<String, ObjectFactory<? >> singletonFactories = new HashMap(16);Copy the code

How does the cache position change during the creation of AB

Last Place