Thursday, August 15, 2013

Difference between thread's context class loader and normal classloader

Class loader basics
JVM provides an hierarchy of class loaders. Let's start with the following class loaders.
Bottstrap class loader
Loads the classes from JAVA_HOME/jre/lib
Extension class loader
Loads the classes from JAVA_HOME/jre/lib/ext
System class loader
Loads the classes from application class path, which is value of the property java.class.path.

Whenever A class A needs to load a class say B, B will be loaded by using the A's classloader. Class loaders in java follows the delegation model. A class loader will pass the request to system class loader, which then will forward the request to extension and extension will forward the request to bootstrap and finally one of the class loaders will load the class.

Thread's context class loader
Let's understand this in jdbc context. JDBC specifications are provided by sun and are part of JAVA_HOME/jre/lib/ext. So all these classes are loaded using extension class loader.




Class loading is hard to understand..need to explain the followings...

  • DriverManager class and drivers registration process in J2SE environment
  • DriverManager class and a driver that is not part of system class loader and whose location will be known at runtime
  • DriverManager and drivers registration in tomcat servlet container
  • Service loader's -> public static <S> ServiceLoader<S> load(Class<S> service) {

No comments:

Post a Comment