当前位置:网站首页>[JVM Loading]---Class Loading Mechanism
[JVM Loading]---Class Loading Mechanism
2022-07-31 05:48:00 【ham programming】
Why design a parent delegation model?
- Sandbox security mechanism: prevent the core API library from being tampered with at will
- Avoid repeated loading of classes: when the parent has already loaded the class, there is no need to let the child classloader load it again to ensure the uniqueness of the loaded class
Class loading mechanism
1. Loading
2. Verifying the [correctness of the file format]
3. Prepare [the static variable memory of the class, and assign it to 0]
4. Analysis [Static method link, convert symbolic reference to direct reference]
5. Initialization: initialize the static variable of the class to the specified value, execute the static code block
Parent delegation model
Start class loader, extend class loader, application class loader, custom loader [inherit loadClass, override findClass]
Bootstrap ClassLoader: This class loader will be stored in the JAVA_HOME/lib directory, or the path specified by the -Xbootclasspath parameter, and is recognized by the virtual machine (only by file name)Recognition, such as rt.jar, the class library whose name does not match will not be overloaded even if it is placed in the lib directory)
Extension ClassLoader (Extension ClassLoader): This class loader is implemented by sun.misc.Launcher$ExtClassLoader, which is responsible for inclusion in the JAVA_HOME/lib/ext directory, or specified by the java.ext.dirs system variableAll class libraries in the path.Developers can use the extension class loader directly.
Application ClassLoader: This class loader is implemented by sun.misc.Launcher$AppClassLoader.Since this class loader is the return value of the getSystemClassLoader method of ClassLoader, it also becomes the system class loader.It is responsible for loading the class library specified on the user's class path (ClassPath).Developers can use this class loader directly. If the application has not defined its own class loader, in general, this is the default class loader in the program
Why break the parental delegation model?
- Effectively resolve the package conflicts in the project, and import the same classes at the same time, but the jar packages are different, and can be imported without exception.The classic representatives are the tomcat and SPI protocols.
边栏推荐
猜你喜欢
随机推荐
剑指offer基础版 --- 第22天
16 【打包上线 图片懒加载】
数据库上机实验2 单表查询和嵌套查询
数字孪生将成为进入“元宇宙”一项重要的途径
Sword Point Offer Special Assault Edition ---- Day 1
小白学爬虫——爬虫入门
gin框架学习-Gin框架和Gorm框架搭建一个简单的API微服务
剑指offer基础版 ----- 第25天
初识正则表达式
剑指offer基础版 ---- 第27天
win11中利用IIS10搭建asp网站
File operations in C language (1)
NFT:数字所有权的核心
闭包(五)----一个常见的循环
C语言实验三 选择结构程序设计
数据库上机实验3 连接查询和分组查询
Redis 事务学习有感
剑指offer基础版 ---- 第29天
03 【数据代理 事件处理】
踏上编程之路,你必须要干的几件事