zoukankan      html  css  js  c++  java
  • Spring源码学习相关记录

    Spring单例实现:

        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 != NULL_OBJECT ? singletonObject : null);
        }

    Spring懒加载:

    private Map<String, Object> getHandlerMappings() {
            if (this.handlerMappings == null) {
                synchronized (this) {
                    if (this.handlerMappings == null) {
                        try {
                            Properties mappings =
                                    PropertiesLoaderUtils.loadAllProperties(this.handlerMappingsLocation, this.classLoader);
                            if (logger.isDebugEnabled()) {
                                logger.debug("Loaded NamespaceHandler mappings: " + mappings);
                            }
                            Map<String, Object> handlerMappings = new ConcurrentHashMap<String, Object>(mappings.size());
                            CollectionUtils.mergePropertiesIntoMap(mappings, handlerMappings);
                            this.handlerMappings = handlerMappings;
                        }
                        catch (IOException ex) {
                            throw new IllegalStateException(
                                    "Unable to load NamespaceHandler mappings from location [" + this.handlerMappingsLocation + "]", ex);
                        }
                    }
                }
            }
            return this.handlerMappings;
        }
  • 相关阅读:
    Kaggle & Machine Learning
    练习题目总结
    日常练习//算法类
    论文阅读
    codeforces专项
    10.26—11.1
    常见算法笔记
    DM/ML学习实践(一)
    Python常见代码
    HDU 4251 --- 主席树(划分树是正解)
  • 原文地址:https://www.cnblogs.com/caiyao/p/10141284.html
Copyright © 2011-2022 走看看