SingletonBeanRegistry是一個很是重要的接口,用於註冊,得到,管理singleton對象。java
SingletonBeanRegistry目前惟一的實現是DefaultSingletonBeanRegistry,DefaultSingletonBeanRegistry不單單實現了SingletonBeanRegistry接口,還管理,維護了singlenton其餘方面的東西。spring
public interface SingletonBeanRegistry { void registerSingleton(String beanName, Object singletonObject); Object getSingleton(String beanName); boolean containsSingleton(String beanName); String[] getSingletonNames(); int getSingletonCount(); Object getSingletonMutex(); }
private final Map<String, Object> singletonObjects = new ConcurrentHashMap<String, Object>(256);
singletonObjects 保存全部單例對象併發
private final Map<String, ObjectFactory<?>> singletonFactories = new HashMap<String, ObjectFactory<?>>(16);
singletonFactories 保存全部單例ObjectFactory框架
private final Map<String, Object> earlySingletonObjects = new HashMap<String, Object>(16);
earlySingletonObjects線程
private final Set<String> registeredSingletons = new LinkedHashSet<String>(256);
registeredSingletons 保存全部單例對象的名字。registeredSingletons= singletonObjects.keySet() + singletonFactories.keySet()設計
private final Set<String> singletonsCurrentlyInCreation = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>(16));
singletonsCurrentlyInCreation 做用是解決單例對象只會建立一次,當建立一個單例對象的時候會向singletonsCurrentlyInCreation添加beanName,另一個線程建立的時候,也會添加beanname到singletonsCurrentlyInCreation,add方法返回false就報異常code
private final Set<String> inCreationCheckExclusions = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>(16));
inCreationCheckExclusions存在的beanName,能夠併發建立。對象
private Set<Exception> suppressedExceptions;
suppressedExceptions 做用當從ObjectFactory得到對象時出現異常,把suppressedExceptions的異常一併拋出。做用不大。接口
private boolean singletonsCurrentlyInDestruction = false;
singletonsCurrentlyInDestruction 做用是當AbstractApplicationContext 銷燬的時候,會銷燬beanFactory裏面全部單例對象。銷燬全部單例對象的時候,singletonsCurrentlyInDestruction設爲true。在getSingleton的時候,識別singletonsCurrentylInDestruction就拒絕得到bean。並報異常。ci
private final Map<String, Object> disposableBeans = new LinkedHashMap<String, Object>();
保存須要銷燬的beans。
private final Map<String, Set<String>> containedBeanMap = new ConcurrentHashMap<String, Set<String>>(16);
整個沒有用。全局查看了調用連,沒有一個連有實際做用的。
private final Map<String, Set<String>> dependentBeanMap = new ConcurrentHashMap<String, Set<String>>(64); private final Map<String, Set<String>> dependenciesForBeanMap = new ConcurrentHashMap<String, Set<String>>(64);
頭疼的dependent。@DependsOn註解以及在spring boot體系裏面其餘與之相關的註解。的關係都會註冊在這裏面。可能還有其餘的方式得到depend,可是這種方式,隱藏得太深了。鳥菜啊,實在不想看了。