当前位置:网站首页>JVM类加载机制
JVM类加载机制
2022-06-27 05:57:00 【季风泯灭的季节】
一、类加载步骤
JVM采用的是懒加载机制,即只有类在被使用时才加载。类的加载主要可分为以下几步:
加载:即把类字节码文件加载到内存,在一步会在内存中生成一个代表这个类的java.lang.Class对象,作为方法区这个类的各种数据的访问入口。
验证:校验字节码文件的准确性,每个字节码文件都有固定的格式,以此来校验字节码文件是否被损坏。
准备:给静态变量分配内存空间并赋与默认值。
解析:将符号引用替换为直接引用,该阶段会把一些静态方法(符号引用,比如 main()方法)替换为指向数据所在内存的指针或句柄等(直接引用),这是所谓的静态链接过程(类加载期间完成),动态链接是在程序运行期间完成的将符号引用替换为直接引用。
初始化:对类变量初始化赋值,并执行静态代码块。
二、类加载器
JVM的类加载主要有四类加载器来配合完成。
三、类加载机制
JVM的类加载机制采用的是双亲委派机制,当加载一个类时,如果使用自定义类加载器,则从自定义加载器查看该加载器是否加载过此类,如果没有则委托上层的应用程序类加载器去加载,在加载时,同样的检查当前类加载器是否加载过此类,如果没有则委托上层的扩展类加载器去加载。在加载时,同样的检查当前类加载器是否加载过此类,没有则委托上层的引导类加载器去加载,在加载时,同样的检查当前类加载器是否加载过此类,如果没有,则由引导类加载器去加载此类,如果在引导类加载器管辖的路径下没加载到此类,则有下层的扩展类程序类加载器去加载,如果在扩展类加载器管辖的路径下没加载到此类,则有下层的应用程序类加载器去加载;如果在应用程序类加载器管辖的路径下没加载到此类,则有下层的自定义类加载器去加载;再加载不到则抛出异常。可以总结成一句话:从下往上检查类是否被加载过,从上往下去加载类。

四、双亲委派机制的意义
五、全盘负责委托机制
六、Tomcat打破双亲委派机制
tomcat为什么不用双亲委派机制?
一个tomcat可能运行多个应用程序,而且这个多个应用程序引用了同一个类的不同版本,所以,从双亲委派机制保证类只加载一份的特点不符合tomcat的业务场景需求。
tomcat如何保证jps的热加载?

边栏推荐
- 1317. convert an integer to the sum of two zero free integers
- [622. design cycle queue]
- Codeforces Round #802 (Div. 2)
- 双位置继电器JDP-1440/DC110V
- The SCP command is used in the expect script. The perfect solution to the problem that the SCP command in the expect script cannot obtain the value
- Webrtc series - Nomination and ice of 7-ice supplement for network transmission_ Model
- Double position relay jdp-1440/dc110v
- Change the status to the corresponding text during MySQL query
- 双位置继电器RXMVB2 R251 204 110DC
- 项目-h5列表跳转详情,实现后退不刷新,修改数据则刷新的功能(记录滚动条)
猜你喜欢

Asp.Net Core6 WebSocket 简单案例

Multithreading basic part2

JS to implement bidirectional data binding

双位置继电器HJWS-9440

30 SCM common problems and solutions!

Assembly language - Wang Shuang Chapter 13 int instruction - Notes

开门小例子学习十种用例图

免费的 SSH 和 Telnet 客户端PuTTY

openstack实例重启状态就会变成错误处理方法,容器搭建的openstack重启计算节点compute服务方法,开机提示Give root password for maintenance处理方法
![[FPGA] realize the data output of checkerboard horizontal and vertical gray scale diagram based on bt1120 timing design](/img/80/c258817abd35887c0872a3286a821f.png)
[FPGA] realize the data output of checkerboard horizontal and vertical gray scale diagram based on bt1120 timing design
随机推荐
Unity中跨平臺獲取系統音量
【QT小记】QT中正则表达式QRegularExpression的基本使用
Junda technology - centralized monitoring scheme for multi brand precision air conditioners
双位置继电器HJWS-9440
Mechanical transcoding journal [17] template, STL introduction
爬虫学习5---反反爬之识别图片验证码(ddddocr和pytesseract实测效果)
Codeforces Round #802 (Div. 2)
Wechat applet refreshes the current page
JS to implement bidirectional data binding
洛谷P4683 [IOI2008] Type Printer 题解
Obtenir le volume du système à travers les plateformes de l'unit é
Built in functions of spark
【Cocos Creator 3.5.1】event. Use of getbutton()
【Cocos Creator 3.5.1】input.on的使用
多线程基础部分Part 1
C Primer Plus 第11章_字符串和字符串函数_代码和练习题
The form verifies the variables bound to the V-model, and the solution to invalid verification
Spark 之 WholeStageCodegen
IAR Systems全面支持芯驰科技9系列芯片
Database - index