六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 101|回复: 0

The J2SE Class Loader Architecture

[复制链接]

升级  60%

6

主题

6

主题

6

主题

童生

Rank: 1

积分
30
 楼主| 发表于 2013-2-7 19:25:35 | 显示全部楼层 |阅读模式
5.  The J2SE Class Loader Architecture
5.1.  Class Loader Hierarchy
   


Class Loader hierarchy
Each class loader (except the bootstrap class loader) has a parent class loader

Class loaders created automatically by the JVM
Bootstrap class loader: Core classes
Extension class loader: Installed extension classes
System class loader: Classes on the class path

User-defined class loaders created by the program
The system class loader is the parent class loader by default
Another parent class loader can be specified explicitly

Each thread has an associated context class loader
Default context class loader is the system class loader
A different context class loader can be specified by calling Thread.setContextClassLoader()
Obtain a thread's context class loader by calling Thread.getContextClassLoader()

Delegation model
When asked to load a class, a class loader first asks its parent to load the class
If the parent succeeds, the class loader returns the class from the parent
If the parent fails, the class loader attempts to load the class itself
This recurses up the hierarchy — thus, the class loader hierarchy is searched from the top back down to the starting point

Which class loader is used?
You can explicitly load a class into a class loader by calling the class loader's loadClass() method
If a class needs to be loaded and a classloader is not explicitly specified -- e.g., a new statement is executed -- the class is loaded into the same class loader that loaded the class that contains the code that is executing


http://www.cs.rit.edu/~ark/lectures/cl/05_01_00.html
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表