当前位置:网站首页>JVM有哪些类加载机制?
JVM有哪些类加载机制?
2022-07-01 21:47:00 【詹Sir(开源字节)】
JVM类加载机制有哪些?
1、全盘负责,当一个类加载器负责加载某个Class时,该Class所依赖的和引用的其他Class也将由该类加载器负责载入,除非显示使用另外一个类加载器来载入
2、父类委托,先让父类加载器试图加载该类,只有在父类加载器无法加载该类时才尝试从自己的类路径中加载该类
3、缓存机制,缓存机制将会保证所有加载过的Class都会被缓存,当程序中需要使用某个Class时,类加载器先从缓存区寻找该Class,只有缓存区不存在,系统才会读取该类对应的二进制数据,并将其转换成Class对象,存入缓存区。这就是为什么修改了Class后,必须重启JVM,程序的修改才会生效
4、双亲委派机制, 如果一个类加载器收到了类加载的请求,它首先不会自己去尝试加载这个类,而是把请求委托给父加载器去完成,依次向上,因此,所有的类加载请求最终都应该被传递到顶层的启动类加载器中,只有当父加载器在它的搜索范围中没有找到所需的类时,即无法完成该加载,子加载器才会尝试自己去加载该类。
双亲委派机制过程?
1、当AppClassLoader加载一个class时,它首先不会自己去尝试加载这个类,而是把类加载请求委派给父类加载器ExtClassLoader去完成。
2、当ExtClassLoader加载一个class时,它首先也不会自己去尝试加载这个类,而是把类加载请求委派给BootStrapClassLoader去完成。
3、如果BootStrapClassLoader加载失败(例如在$JAVA_HOME/jre/lib里未查找到该class),会使用ExtClassLoader来尝试加载;
4、若ExtClassLoader也加载失败,则会使用AppClassLoader来加载,如果AppClassLoader也加载失败,则会报出异常ClassNotFoundException。
如若转载,请注明出处:开源字节 https://sourcebyte.cn/article/174.html
边栏推荐
- spark analyze命令使用及其作用 map join broadcast join 广播join
- 100年仅6款产品获批,疫苗竞争背后的“佐剂”江湖
- 【直播回顾】战码先锋首期8节直播完美落幕,下期敬请期待!
- Design and practice of new generation cloud native database
- RestTemplate 远程调用工具类
- Internet of things RFID, etc
- 使用闭包实现点击按钮切换 toggle
- Pytorch sharpening chapter | argmax and argmin functions
- Relationship and difference between enterprise architecture and project management
- 多种智能指针
猜你喜欢

3DE 资源没东西或不对

指标陷阱:IT领导者易犯的七个KPI错误

plantuml介绍与使用

Recent public ancestor offline practice (tarjan)

GenICam GenTL 标准 ver1.5(4)第五章 采集引擎

AirServer2022最新版功能介绍及下载

Spark interview questions

YOLOv5.5 调用本地摄像头

Getting started with the lockust series

Do you want to make up for the suspended examination in the first half of the year? Including ten examinations for supervision engineers, architects, etc
随机推荐
3DE 资源没东西或不对
PHP reflective XSS, reflective XSS test and repair
GenICam GenTL 标准 ver1.5(4)第五章 采集引擎
Qtreeview+qabstractitemmodel custom model: the third of a series of tutorials [easy to understand]
Count the number of each character in the character
What is the difference between consonants and Initials? (difference between initials and consonants)
函数基本学习之一
100年仅6款产品获批,疫苗竞争背后的“佐剂”江湖
In the past 100 years, only 6 products have been approved, which is the "adjuvant" behind the vaccine competition
Mask wearing detection method based on yolov5
Airserver mobile phone third-party screen projection computer software
Flume interview questions
Four methods of JS array splicing [easy to understand]
Indicator trap: seven KPI mistakes that it leaders are prone to make
13th Blue Bridge Cup group B national tournament
Show member variables and methods in classes in idea
详解Kubernetes网络模型
[live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
高攀不起的希尔排序,直接插入排序
A debugging to understand the slot mechanism of redis cluster