Spring源码 18 IOC refresh方法13
参考源
https://www.bilibili.com/video/BV1tR4y1F75R?spm_id_from=333.337.search-card.all.click
https://www.bilibili.com/video/BV12Z4y197MU?spm_id_from=333.999.0.0
《Spring源码深度解析(第2版)》
版本
本文章基于 Spring 5.3.15
Spring IOC 的核心是
AbstractApplicationContext的refresh方法。
其中一共有 13 个主要方法,这里分析第 13 个:resetCommonCaches。
1 AbstractApplicationContext
1-1 清空缓存
resetCommonCaches()
protected void resetCommonCaches() {
// 清空反射缓存
ReflectionUtils.clearCache();
// 清空注解缓存
AnnotationUtils.clearCache();
// 清空并发缓存
ResolvableType.clearCache();
// 清空类加载器
CachedIntrospectionResults.clearClassLoader(getClassLoader());
}
1-2 清空反射缓存
ReflectionUtils.clearCache()
2 ReflectionUtils
private static final Map<Class<?>, Method[]> declaredMethodsCache = new ConcurrentReferenceHashMap<>(256);
private static final Map<Class<?>, Field[]> declaredFieldsCache = new ConcurrentReferenceHashMap<>(256);
public static void clearCache() {
declaredMethodsCache.clear();
declaredFieldsCache.clear();
}
1 AbstractApplicationContext
1-2 清空注解缓存
AnnotationUtils.clearCache()
public static void clearCache() {
// 清空类型映射缓存
AnnotationTypeMappings.clearCache();
// 清空注解扫描缓存
AnnotationsScanner.clearCache();
}
3-1 清空类型映射缓存
AnnotationTypeMappings.clearCache()
4 AnnotationTypeMappings
private static final Map<AnnotationFilter, Cache> standardRepeatablesCache = new ConcurrentReferenceHashMap<>();
private static final Map<AnnotationFilter, Cache> noRepeatablesCache = new ConcurrentReferenceHashMap<>();
static void clearCache() {
standardRepeatablesCache.clear();
noRepeatablesCache.clear();
}
3 AnnotationUtils
3-1 清空注解扫描缓存
AnnotationsScanner.clearCache()
5 AnnotationsScanner
private static final Map<AnnotatedElement, Annotation[]> declaredAnnotationCache = new ConcurrentReferenceHashMap<>(256);
private static final Map<Class<?>, Method[]> baseTypeMethodsCache = new ConcurrentReferenceHashMap<>(256);
static void clearCache() {
declaredAnnotationCache.clear();
baseTypeMethodsCache.clear();
}
1 AbstractApplicationContext
1-2 清空并发缓存
ResolvableType.clearCache()
6 ResolvableType
private static final ConcurrentReferenceHashMap<ResolvableType, ResolvableType> cache = new ConcurrentReferenceHashMap<>(256);
public static void clearCache() {
cache.clear();
SerializableTypeWrapper.cache.clear();
}
1 AbstractApplicationContext
1-2 清空类加载器
CachedIntrospectionResults.clearClassLoader(getClassLoader())
7 CachedIntrospectionResults
static final Set<ClassLoader> acceptedClassLoaders = Collections.newSetFromMap(new ConcurrentHashMap<>(16));
static final ConcurrentMap<Class<?>, CachedIntrospectionResults> strongClassCache = new ConcurrentHashMap<>(64);
static final ConcurrentMap<Class<?>, CachedIntrospectionResults> softClassCache = new ConcurrentReferenceHashMap<>(64);
public static void clearClassLoader(@Nullable ClassLoader classLoader) {
// 判断是否在类加载器下面
acceptedClassLoaders.removeIf(registeredLoader -> isUnderneathClassLoader(registeredLoader, classLoader));
strongClassCache.keySet().removeIf(beanClass -> isUnderneathClassLoader(beanClass.getClassLoader(), classLoader));
softClassCache.keySet().removeIf(beanClass -> isUnderneathClassLoader(beanClass.getClassLoader(), classLoader));
}
7-1 判断是否在类加载器下面
isUnderneathClassLoader(registeredLoader, classLoader)
private static boolean isUnderneathClassLoader(@Nullable ClassLoader candidate, @Nullable ClassLoader parent) {
if (candidate == parent) {
return true;
}
if (candidate == null) {
return false;
}
ClassLoader classLoaderToCheck = candidate;
while (classLoaderToCheck != null) {
classLoaderToCheck = classLoaderToCheck.getParent();
if (classLoaderToCheck == parent) {
return true;
}
}
return false;
}
Spring源码 18 IOC refresh方法13的更多相关文章
- Spring源码 07 IOC refresh方法2
参考源 https://www.bilibili.com/video/BV1tR4y1F75R?spm_id_from=333.337.search-card.all.click https://ww ...
- Spring源码 16 IOC refresh方法11
参考源 https://www.bilibili.com/video/BV1tR4y1F75R?spm_id_from=333.337.search-card.all.click https://ww ...
- Spring源码 17 IOC refresh方法12
参考源 https://www.bilibili.com/video/BV1tR4y1F75R?spm_id_from=333.337.search-card.all.click https://ww ...
- Spring源码 15 IOC refresh方法10
参考源 https://www.bilibili.com/video/BV1tR4y1F75R?spm_id_from=333.337.search-card.all.click https://ww ...
- Spring源码 14 IOC refresh方法9
参考源 https://www.bilibili.com/video/BV1tR4y1F75R?spm_id_from=333.337.search-card.all.click https://ww ...
- Spring源码 11 IOC refresh方法6
参考源 https://www.bilibili.com/video/BV1tR4y1F75R?spm_id_from=333.337.search-card.all.click https://ww ...
- Spring源码 09 IOC refresh方法4
参考源 https://www.bilibili.com/video/BV1tR4y1F75R?spm_id_from=333.337.search-card.all.click https://ww ...
- Spring源码 08 IOC refresh方法3
参考源 https://www.bilibili.com/video/BV1tR4y1F75R?spm_id_from=333.337.search-card.all.click https://ww ...
- Spring源码 06 IOC refresh方法1
参考源 https://www.bilibili.com/video/BV1tR4y1F75R?spm_id_from=333.337.search-card.all.click https://ww ...
随机推荐
- 05-STL
Day01 笔记 1 STL概论 1.1 STL六大组件 1.1.1 容器.算法.迭代器.仿函数.适配器.空间配置器 1.2 STL优点 1.2.1 内建在C++编译器中,不需要安装额外内容 1.2. ...
- thusc2022游记
DAY -1: 刷往年相关的题 DAY 0: 刷会儿题了,搞电脑,下obs.不过,发现电脑出了很多问题. obs没有录频效果,因为卡,杀毒软件把vc++全都删了.因此无dll文件错误,搞了一晚上都没搞 ...
- singlelinklist
C++实现单链表 阅读先知 链表是一种动态数据结构,他的特点是用一组任意的存储单元(可以是连续的,也可以是不连续的)存放数据元素. 链表中每一个元素成为"结点",每一个结点都是由数 ...
- 区分 python 爬虫或者是写自动化脚本时遇到的 content与text的作用
通常在使用过程中或许我们能够轻而易举的会使用requsts模块中的content 与 text ,从print结果来看根本看不出任何区别: 总结精髓,text 返回的是unicode 型的数据,一般是 ...
- JZOJ 5409 Fantasy & NOI 2010 超级钢琴 题解
其实早在 2020-12-26 的比赛我们就做过 5409. Fantasy 这可是紫题啊 题目大意 给你一个序列,求长度在 \([L,R]\) 区间内的 \(k\) 个连续子序列的最大和 题解 如此 ...
- 技术分享 | Appium 用例录制
原文链接 下载及安装 下载地址: https://github.com/appium/appium-desktop/releases 下载对应系统的 Appium 版本,安装完成之后,点击 " ...
- VMware Workstation 虚拟机详细安装教程
一.介绍篇 VMware Workstation 16 Pro是VMware(威睿公司)于2021年最新发布的一代虚拟机软件,软件的中文名是"VMware 工作站 16 专业版". ...
- sharepoint 配置失败,已引发类型为System.ArgumentException的异常。其他异常信息:domainName参数不支持指定的值。
解决方法:在域控制器中加入sharepoint计算机,设置为administrators组中
- 一篇文章带你深入浅出Vuex
在写Vuex之前,我们先用一个简单的例子来实现一个小demo 大家都知道Vue的父传子用在很多场景,比如像这样: 父组件: <template> <div id="app& ...
- IDEA项目启动乱码小方块
在看完执行了网上各种文章之后,我发现没有一个适合我的. 最终,终于,在朋友的远程帮助下解决了. 如果你还有这个问题的话,可以试一下这个: 右键项目,打开终端,执行下面这个命令(手动指定一下maven ...