Parents delegation mechanism JVM class loader

In the parent delegation mechanism, each of the loaders in the parent-child relationships forming a tree structure (logical sense) , roots loader addition, the remaining class loader has one and only one parent loader.

 

Parent class loader delegation mechanism

 

 Return ClassLoader String class

public class MyTest7 {
    public static void main(String[] args)  throws  Exception{
        Class<?> clazz = Class.forName("java.lang.String");
        ClassLoader classLoader = clazz.getClassLoader();
        System.out.println(classLoader);
    }

}

  Back to Results

null

  Description null class loader is to start classLoader

 

Returns from the class defined ClassLoader

public class MyTest7 {
    public static void main(String[] args)  throws  Exception{
      
        Class<?> clazz2 = Class.forName("com.example.jvm.classloader.C");
        ClassLoader classLoader2 = clazz2.getClassLoader();
        System.out.println(classLoader2);
    }

}

class C{

}

  Back to Results

sun.misc.Launcher$AppClassLoader@18b4aac2

  

 

Guess you like

Origin www.cnblogs.com/linlf03/p/10991374.html