当前位置:网站首页>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 !
边栏推荐
- The type of MySQL index (single column index, combined index, BTREE index, clustered index, etc.)
- Unity高版本退回低版本报错问题
- LeetCode 2249. Count the number of grid points in the circle
- ENVI_ Idl: use the inverse distance weight method to select the nearest n points for interpolation (bottom implementation) and output them to GeoTIFF format (the effect is equivalent to the inverse di
- Journal日志与oplog日志的区别
- 虚拟化排错概论
- Definable 6G security architecture
- 466-82(3、146、215)
- Over fitting and under fitting
- Codeforces - 587e (linear basis + segment tree + difference)
猜你喜欢

JVM钩子hooks函数

Google Earth Engine——Hansen Global Forest Change v1.8 (2000-2020) 森林覆盖度和森林损失量数据集

Ppde Q2 welcome | welcome 22 AI developers to join the propeller developer technical expert program!

要想组建敏捷团队,这些方法不可少

Documents required for military product development process - advanced version

LeetCode 2335. Minimum total time required to fill the cup

Second classification learning is extended to multi classification learning

Today's sleep quality record 79 points
![[leetcode weekly replay] 302 weekly 20220717](/img/38/446db9b4755f8b30f9887faede7e95.png)
[leetcode weekly replay] 302 weekly 20220717

Mysql优化系列之limit查询
随机推荐
Unity高版本退回低版本报错问题
2022/7/14
A fastandrobust volutionalneuralnetwork based defect detection model inproductqualitycontrol reading notes
LeetCode 2335. Minimum total time required to fill the cup
Use and principle of ThreadLocal variable
Goldfish rhca memoirs: cl210 describes the openstack control plane -- identify the overcloud control platform service + chapter experiment
Ppde Q2 welcome | welcome 22 AI developers to join the propeller developer technical expert program!
Introduction to virtualization troubleshooting
委派双亲之类加载器
Second classification learning is extended to multi classification learning
A fastandrobust convolutionalneuralnetwork-based defect detection model inproductqualitycontrol-閱讀筆記
Summary of port mirroring methods with VDS or NSX under vSphere
mpu9250 ky9250姿态、角度模块和mpu9250 mpl dma对比
Opencv programming: opencv3 X trains its own classifier
Conversion of unity3d model center point (source code)
Download of common getshell tools
Daily question brushing record (26)
Cmake common commands (V)
Detailed explanation of Euler angle, axis angle, quaternion and rotation matrix
Tier defect detection using full revolutionary network