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

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

边栏推荐
- Spark 之 WholeStageCodegen
- Program ape learning Tiktok short video production
- Codeforces Round #802 (Div. 2)
- 开门小例子学习十种用例图
- KubeSphere 集群配置 NFS 存储解决方案-收藏版
- 【QT小记】QT元对象系统简单认识
- C# netcore中 配置帮助类IConfiguration
- Double position relay jdp-1440/dc110v
- 【Cocos Creator 3.5.1】this.node.getPosition(this._curPos)的使用
- 程序猿学习抖音短视频制作
猜你喜欢

leetcode299周赛记录

The restart status of the openstack instance will change to the error handling method. The openstack built by the container restarts the compute service method of the computing node and prompts the gi

Kubesphere cluster configuration NFS storage solution - favorite

双位置继电器HJWS-9440

30 SCM common problems and solutions!

树莓派4B上运行opcua协议DEMO接入kubeedge

Asp.Net Core6 WebSocket 简单案例

LeetCode-515. 在每个树行中找最大值

块级元素&行内元素

【QT小作】使用结构体数据生成读写配置文件代码
随机推荐
Kubesphere cluster configuration NFS storage solution - favorite
Wholestagecodegen of spark
Win 10 如何打开环境变量窗口
Opencv implements object tracking
微信小程序WebSocket使用案例
Spark's projection
Codeforces Round #802 (Div. 2)
leetcode298周赛记录
Database - index
汇编语言-王爽 第9章 转移指令的原理-笔记
The restart status of the openstack instance will change to the error handling method. The openstack built by the container restarts the compute service method of the computing node and prompts the gi
LeetCode-515. 在每个树行中找最大值
使用 WordPress快速个人建站指南
Built in functions of spark
Small program of C language practice (consolidate and deepen the understanding of knowledge points)
Two position relay rxmvb2 r251 204 110dc
使用域名转发mqtt协议,避坑指南
洛谷P2939 [USACO09FEB]Revamping Trails G 题解
Jump details of item -h5 list, and realize the function of not refreshing when backing up, and refreshing when modifying data (record scroll bar)
My opinion on test team construction