当前位置:网站首页>Delegate parents and other loaders
Delegate parents and other loaders
2022-07-19 11:17:00 【TaoYuanming of the Western Wei Dynasty】

author : TaoYuanming of the Western Wei Dynasty
Blog : https://blog.springlearn.cn/
TaoYuanming of the Western Wei Dynasty
Don't laugh at the young Jianghu dream , Who doesn't dream of Jianghu
- BootStrap ClassLoader: It's called the boot class loader , yes Java The top-level classloader in the class loading hierarchy , Responsible for loading JDK Core class library in , Such as :rt.jar、resources.jar、charsets.jar etc. , The following procedure can be used to obtain where the class loader loads the relevant jar or class file :
- Extension ClassLoader: It's called an extended class loader , Responsible for loading Java The extended class library of , The default load JAVA_HOME/jre/lib/ext/ All of this jar.
- App ClassLoader: It's called a system class loader , Responsible for loading the application classpath All under directory jar and class file .
One 、 Class loader
Class is loaded in JVM External implementation of . For any class , Must be established by the class loader that loads it and the class itself Java Uniqueness in virtual machines .JVM Provide medium class loader .
Two 、 Start class loader (Bootstrap ClassLoader)
Responsible for loading JAVA_HOME\lib In the directory , Or through -Xbootclasspath Parameter specifies... In the path , And be Virtual machine approval ( Identify by file name , Such as rt.jar) Class .

3、 ... and 、 Extend the classloader (Extension ClassLoader)
Responsible for loading JAVA_HOME\lib\ext In the directory , Or through java.ext.dirs The system variable specifies the class in the path library .

Four 、 Application class loader (Application ClassLoader)
Responsible for loading user paths (classpath) Class library . JVM Load the class through the parent delegation model , Of course, we can also inherit java.lang.ClassLoader Implement custom class loader .

5、 ... and 、 Explanation of principle
ClassLoader The parent delegation model is used to search for the properties of classes , Every ClassLoader Instance has a reference to the parent loader ( Not an inherited relationship , It's an inclusive relationship ), Virtual machine built-in classloader (Bootstrap ClassLoader) There is no parent loader in itself , But it can be used for other purposes ClassLoader Instance's parent loader . When one ClassLoader When an instance needs to load a class , It will try to search for a class in person before , Delegate this task to its parent loader first , This process is checked from top to bottom , First, the top-level class loader Bootstrap ClassLoader Attempt to load , If it's not loaded into , Then transfer the task to Extension ClassLoader Attempt to load , If it doesn't load into , Is passed on to App ClassLoader Loading , If it doesn't load either , Is returned to the originator of the delegate , From it to the specified file system or network, etc URL Load the class in . If none of them are loaded into this class , Throw out ClassNotFoundException abnormal . Otherwise, the found class will be generated into a class definition , And load it into memory , Finally, return the in memory Class Instance object .
6、 ... and 、 Why use a parent delegation model ?
Because this can avoid repeated loading , When the father has loaded the class , There is no need ClassLoader Load again . Considering the safety factor , Let's think about , If you don't use this delegation mode , Then we can use the customized String To dynamically replace java The core api Type defined in , There will be a very big security risk , And the way parents entrust , This can be avoided , because String Already booted class loader at boot time (Bootstrcp ClassLoader) load , So user defined ClassLoader Never load a self written String, Unless you change JDK in ClassLoader Default algorithm for search class .
7、 ... and 、 however JVM When searching for classes , How to judge two class It's the same ?
JVM In judging two class Is it the same , It's not just about judging whether two class names are the same , And to determine whether it is loaded by the same classloader instance . Only when both are satisfied ,JVM I think these two class It's the same . Even two class It's the same class Bytecode , If two different ClassLoader Instance loaded ,JVM I think they are two different class.
/**
* rt Catalog :
* load rt.jar Class loader for
*/
ClassLoader rtClassLoader = StringBuffer.class.getClassLoader();
System.out.println(rtClassLoader);
/**
* lib/ext Expansion pack,
* [email protected]
*/
ClassLoader extClassLoader = EventID.class.getClassLoader();
System.out.println(extClassLoader);
/**
* Current Application Loader
* [email protected]
*/
ClassLoader classLoader = BaseSyntaxTest.class.getClassLoader();
System.out.println(classLoader);
/**
* [email protected]
*/
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
System.out.println(currentClassLoader);
Finally, please pay attention , Request subscription , Thanks for reading !
边栏推荐
- Detailed explanation of multiple linear regression
- Unity3d 读取mpu9250 例子原代码
- Future applications and technical challenges of backscatter communication
- What should I do if I can't see any tiles on SAP Fiori launchpad?
- Tire Defect Detection Using Fully Convolutional Network-论文阅读笔记
- Set the interface language of CMD command prompt window to English
- Avi Deployment Guide (2): overview of AVI architecture
- How much money can you make by inventing flash memory? This is a Japanese dog blood story
- AT5147-[AGC036D]Negative Cycle【dp,模型转换】
- Similarities and differences between OA system and MES system
猜你喜欢

synchronized锁升级

数据库锁的介绍与InnoDB共享,排他锁

LeetCode 2331. Calculate the value of Boolean binary tree (tree traversal)
![Some methods of early MCU encryption [get data in the comment area]](/img/14/8e1dcb799d8a3c0aefcac09be9dc51.png)
Some methods of early MCU encryption [get data in the comment area]

一个报错, Uncaught TypeError: ModalFactory is not a constructor

Avi Deployment Guide (2): overview of AVI architecture
![[leetcode weekly replay] 302 weekly 20220717](/img/38/446db9b4755f8b30f9887faede7e95.png)
[leetcode weekly replay] 302 weekly 20220717

Download of common getshell tools

Tencent cloud server uses image to deploy WordPress personal website!

LeetCode 745. 前缀和后缀搜索
随机推荐
Thinking about the integrated communication of air, space and earth based on the "7.20 Zhengzhou rainstorm"
Paper notes: mind the gap an empirical evaluation of impaction ofmissing values techniques in timeseries
Introduction to replacement technology of SAP ABAP CDs view view
ThreadLocal变量使用及原理
数据库锁的介绍与InnoDB共享,排他锁
Definable 6G security architecture
Avi Deployment Guide (2): overview of AVI architecture
Qt 两个重载QListWidget控件对象实现selectitem drag拖拽
常见分布式锁介绍
腾讯云服务器利用镜像部署WordPress个人网站!
一个报错, Uncaught TypeError: ModalFactory is not a constructor
Ppde Q2 welcome | welcome 22 AI developers to join the propeller developer technical expert program!
XSS.haozi.me刷题
Develop the first Flink app
Today's sleep quality record 79 points
466-82(3、146、215)
Unity3d 模型中心点的转换(源代码)
NVIDIA uses AI to design GPU: the latest H100 has been used, which reduces the chip area by 25% compared with traditional EDA
After summarizing the surface based knowledge of the database
Integrated network architecture and network slicing technology of air, earth and sea