当前位置:网站首页>[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.
边栏推荐
猜你喜欢
随机推荐
元宇宙的前景及四大赛道
Flask-based three-party login process
【ubuntu20.04安装MySQL以及MySQL-workbench可视化工具】
leetcode-每日一题565. 数组嵌套(标记图和并查集)
【JVM加载】---类加载机制
Three-party login using wallet Metamask based on web3.0
vulhub靶场学习日记hackme1
Redis first meeting
【云原生】原来2020.0.X版本开始的OpenFeign底层不再使用Ribbon了
剑指offer基础版 --- 第22天
gin框架学习-JWT认证
年终总结——岁月静好~
【uiautomation】微信好友列表获取(存储到txt中)
利用phpstudy搭建DVWA
闭包(二)
继承、Super,重写、抽象类、抽象方法 1(第七天)
Linux中mysql密码修改方法(亲测可用)
Three handshakes and four waves
1D, 2D, 3D convolution operations in pytorch
C语言实验三 选择结构程序设计