当前位置:网站首页>About the parental delegation mechanism and the process of class loading
About the parental delegation mechanism and the process of class loading
2022-07-06 13:39:00 【Wake up duck, did you program today?】
We wrote java File to final run , He must go through two stages of compilation and class loading , The process of compiling is to put
.java File compiled into .class file , The stage of class loading is to put .class File loading to JVM In memory , Loading finished
You'll get one Class object , We can use new Keyword to instantiate this object , Here's the picture :
The loading process of classes needs to involve
To class loader ,JVM When running, three class loaders will be generated , These three class loaders form a hierarchical relationship , Each loader loads different ranges of jar package , for instance Bootstrap Classloader( Start class loader )
It is mainly responsible for loading java The loading of the core class library is lib Under the table of contents rt.jar and resources.jar etc. ,Extension ClassLoader( Extend the classloader ) Main load lib\ext A... In the catalog jar Bao He class file ,Application ClassLoader( Apply the class loader ), Mainly responsible for the current application classpath All of the following jar Bao He class file , Besides the class loader provided by the processing system itself, you can also use ClassLoader Class to implement the custom loader , To meet the needs of some scenes .
The so-called parental delegation model , According to the hierarchical relationship of class loader , Delegate layer by layer , For example, when we need to load a class When you file , First of all, I will take this class The query and loading of files are delegated to the parent loader to execute , If the parent loader fails to load , Try to load this by yourself class
I think such benefits :
- Security : Because this hierarchical relationship actually represents a kind of priority , That is, all class loading priority should be given to the startup class loader , Then there is no way to destroy some classes in the core class library , For example, write a java.lang.String Finally, it is up to the boot class loader , His writing java.lang.String There is no way to cover the classes in the class library .
- I think this kind of hierarchical design relationship , It can avoid some problems of program confusion caused by repeated loading , If the parent loader has already been loaded , Then there is no need to load the sub loader .
The running result shows :
边栏推荐
猜你喜欢
3. C language uses algebraic cofactor to calculate determinant
更改VS主题及设置背景图片
一段用蜂鸣器编的音乐(成都)
A comprehensive summary of MySQL transactions and implementation principles, and no longer have to worry about interviews
仿牛客技术博客项目常见问题及解答(二)
Caching mechanism of leveldb
[hand tearing code] single case mode and producer / consumer mode
仿牛客技术博客项目常见问题及解答(三)
arduino+DS18B20温度传感器(蜂鸣器报警)+LCD1602显示(IIC驱动)
C语言入门指南
随机推荐
【九阳神功】2022复旦大学应用统计真题+解析
Tyut Taiyuan University of technology 2022 "Mao Gai" must be recited
8. C language - bit operator and displacement operator
MySQL事务及实现原理全面总结,再也不用担心面试
ArrayList的自动扩容机制实现原理
3.C语言用代数余子式计算行列式
Rich Shenzhen people and renting Shenzhen people
[中国近代史] 第五章测验
PriorityQueue (large root heap / small root heap /topk problem)
3. Number guessing game
[the Nine Yang Manual] 2020 Fudan University Applied Statistics real problem + analysis
7. Relationship between array, pointer and array
C language Getting Started Guide
重载和重写的区别
[hand tearing code] single case mode and producer / consumer mode
Conceptual model design of the 2022 database of tyut Taiyuan University of Technology
魏牌:产品叫好声一片,但为何销量还是受挫
5月27日杂谈
Quickly generate illustrations
Change vs theme and set background picture