In-depth analysis and custom class loader Detailed 24_ system platform-specific boot loader class

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_43277087/article/details/102750664

Here Insert Picture Description
The result:
Here Insert Picture Description
the result of the Java program to run it.
If the command is run on the console
Here Insert Picture Description
Here Insert Picture Description
will be based on different directory you run, to yield the corresponding directory system
through the theme, it can be seen, the class loader loads the application directory is also the current directory is the
figure is. (Dot) Contents
Here Insert Picture Description
summary:
Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description
If the
Here Insert Picture Description
root directory modifications loader loads
into the current directory
Here Insert Picture Description
virtual machine initialization error when first loading the Object class
can not find the object class, the virtual machine will not start up
Here Insert Picture Description
question: class loader loads the class to a virtual machine
, however, the class Java class loader itself, how it own virtual machine to load it?
It is loaded by the boot class

Root loader is written in C ++, embedded in the Java Virtual Machine, which is attributable to the jvm part
and application class loader and the extension class loader is responsible for starting the class loader

Here Insert Picture Description
验证扩展类加载器和启动类加载器由谁加载?
Here Insert Picture Description
Here Insert Picture Description
它们都是Launcher类的静态内部类,外部并不能直接访问
那么,我们就先加载Launcher类,加载它的加载器为A,当加载Launcher类时,A加载器会加载Launcher类内部的所有Launcher类依赖的类。

Here Insert Picture Description
Here Insert Picture Description
说明Launcher类由启动类加载器加载的
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
系统类加载器:
Here Insert Picture Description
Here Insert Picture Description
系统属性:java.system.class.loader默认为APPClassLoader
上图中,说明我们可以自定义系统属性:java.system.class.loader作为系统类加载器,取代原来的APPClassLoader

查看java.system.class.loader的默认值:
Here Insert Picture Description
Here Insert Picture Description
说明这个属性,默认是未定义的
没有被定义,那么系统类加载器默认指向APPClassLoader

使用MyTest16作为系统类加载器加载MyTest23
Here Insert Picture Description
Here Insert Picture Description
文档中说明:
这个新的系统类加载器必须有个public构造方法,传入类加载器作为它的委托双亲
Here Insert Picture Description
再次执行此命令
Here Insert Picture Description
说明MyTest16作为系统类加载器成功

但是
Here Insert Picture Description
在Idea中运行此上图程序:
Here Insert Picture Description
当在控制台上执行:
Here Insert Picture Description
为什么呢?
使用Idea运行,系统类加载器的那个属性没有被赋值,还是原来的规则,没变,所以是APPClassLoader

Command on the console using
the property that the system class loader changes the
system class loader is customize the output loader, however, the parent loader this loader is APPClassLoader

Guess you like

Origin blog.csdn.net/qq_43277087/article/details/102750664