当前位置:网站首页>[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.
边栏推荐
猜你喜欢
随机推荐
【云原生】原来2020.0.X版本开始的OpenFeign底层不再使用Ribbon了
uni-app进阶之自定义【day13】
win11中利用IIS10搭建asp网站
wpf wrapPanel居中并从左到右排列
代码块、Package,Import,封装(第六天)
变量的解构赋值
数据库上机实验1 数据库定义语言
sqlmap注入教程 常用指令
Detailed explanation of pointers in C language
02 【el和data的两种写法 MVVM模型】
详解扫雷游戏(C语言)
mac10.14中安装mysqldb
数据库上机实验2 单表查询和嵌套查询
【swagger关闭】生产环境关闭swagger方法
03 【数据代理 事件处理】
【Elastic-Job】分布式调度任务概览篇
leetcode-每日一题558. 四叉树交集(分治递归)
Swordsman Offer Special Assault Edition ---- Day 6
Kubernetes certificate validity period modification
Sword Point Offer Special Assault Edition ---- Day 1









