classLoader

1、classLoader

     java通过类加载机制(classLoader)把class加载到JVM内存中。动态加载:实际使用时才会去加载相关类信息。

2、java提供的classLoader

    BootstrapClassLoader、ExtClassLoader、AppClassLoader

    Bootstrap ClassLoader不继承自ClassLoader,因为它不是一个普通的Java类,底层由C++编写,已嵌入到了JVM内核当中,当JVM启动后,Bootstrap ClassLoader也随着启动,负责加载完核心类库后,并构造Extension ClassLoader和App ClassLoader类加载器。
classLoader
 

		//-- bootstrap classLoader urls.
		URL[] urls = Launcher.getBootstrapClassPath().getURLs();
		for(URL url : urls){
			System.out.println(url);
		}
		
		//----ext class loader urls.
		URLClassLoader extClassLoader = (URLClassLoader)ClassLoader.getSystemClassLoader().getParent();
		System.out.println("ext class loader:");
		System.out.println(extClassLoader);
		
		urls = extClassLoader.getURLs();
		for(URL url : urls){
			System.out.println(url);
		}
		//app class loader urls.
		URLClassLoader appClassLoader = (URLClassLoader)ClassLoader.getSystemClassLoader();
		System.out.println("appclass loader :"+appClassLoader);
		urls = appClassLoader.getURLs();
		for(URL url : urls){
			System.out.println(url);
		}
		

 

bootstrap class loader
file:/C:/Program%20Files/Java/jdk1.6.0_38/jre/lib/resources.jar
file:/C:/Program%20Files/Java/jdk1.6.0_38/jre/lib/rt.jar
file:/C:/Program%20Files/Java/jdk1.6.0_38/jre/lib/sunrsasign.jar
file:/C:/Program%20Files/Java/jdk1.6.0_38/jre/lib/jsse.jar
file:/C:/Program%20Files/Java/jdk1.6.0_38/jre/lib/jce.jar
file:/C:/Program%20Files/Java/jdk1.6.0_38/jre/lib/charsets.jar
file:/C:/Program%20Files/Java/jdk1.6.0_38/jre/lib/modules/jdk.boot.jar
file:/C:/Program%20Files/Java/jdk1.6.0_38/jre/classes
ext class loader:
sun.misc.Launcher$ExtClassLoader@42e816
file:/C:/Program%20Files/Java/jdk1.6.0_38/jre/lib/ext/dnsns.jar
file:/C:/Program%20Files/Java/jdk1.6.0_38/jre/lib/ext/localedata.jar
file:/C:/Program%20Files/Java/jdk1.6.0_38/jre/lib/ext/sunjce_provider.jar
file:/C:/Program%20Files/Java/jdk1.6.0_38/jre/lib/ext/sunmscapi.jar
file:/C:/Program%20Files/Java/jdk1.6.0_38/jre/lib/ext/sunpkcs11.jar
appclass loader :sun.misc.Launcher$AppClassLoader@addbf1
file:/E:/work_icu_basic/icuWsTest/bin/

 

3、classLoader 加载原理

      使用双亲委托模型

4、自定义classLoader

你可能感兴趣的:(ClassLoader)