|
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 |
|