[java] 浅析ClassLoader

类装载器负责寻找类的字节码文件并构造出jvm中对应的对象组件。要经过以下步骤:

1、查找并导入class字节码文件

2、执行校验,解析步骤

3、初始化:对类的静态变量、静态代码块进行初始化工作。

类的初始化工作由ClassLoader以及其子类负责:ClassLoader-->ExtClassLoader-->AppClassLoader。

ClassLoader 负责加载JRE的核心类库,ExtClassLoader负责加载JRE的扩展类库,AppClassLoader负责加载应用Classpath下的jar文件。

public class ClassLoaderTest {
	public static void main(String[] args) {
		ClassLoader cl = Thread.currentThread().getContextClassLoader();
		System.out.println("currrent thread" + cl);
		System.out.println("parent thread"+cl.getParent());
		//根类装载器在java中找不到,native方法实现
		System.out.println("parent parent thread"+cl.getParent().getParent());
		
	}
}

输出信息

currrent threadsun.misc.Launcher$AppClassLoader@6c68bcef
parent threadsun.misc.Launcher$ExtClassLoader@504c2683
parent parent threadnull


类的加载过程中采用“全盘负责委托机制”:委托机制是指类加载过程中优先又父类进行加载,如父类找不到则再由子类加载,全盘负责指:装载类时,其依赖以及引用的类优先用此ClassLoader加载。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值