java virtual machine (11) --- classification of class loader

Java virtual machine (11)-classification of class loader

One, start the class loader (bootstrap class loader, Bootstrap ClassLoader)

  1. This class is implemented in c/c++ language and is nested inside the JVM.
  2. It is used to load the core java library (java_home/jre/lib/rt.jar/resource.jar or the content under the sun.boot.class.path path) and is used to provide the classes needed by the jvm itself.
  3. Does not inherit from java.lang.ClassLoader, no parent loader
  4. Load extension classes and application class loaders, and designate them as their parent class loaders
  5. For security reasons, Bootstrap startup class loader only loads classes whose package names start with java, javax, sun, etc.

Second, the extension class loader (Extension ClassLoader)

  1. Written in java language, implemented by sun.misc.Launcher$ExClassLoader
  2. Derived from the ClassLoader class
  3. The parent class loader is the startup class loader
  4. Load the class library from the directory specified by the java.ext.dirs system property, or load the class library from the jre/lib/ext subdirectory (extension directory) of the jdk installation directory. If the jar created by the user is placed in the secondary directory, it will also be automatically loaded by the extended class loader.

Three, the loader that comes with the virtual machine

Application class loader (system class loader, AppClassLoader)

  1. Written in java language, implemented by sun.misc.Launcher$AppClassLoader
  2. Derived from the ClassLoader class
  3. The parent class loader is the extended class loader
  4. It is responsible for loading the class library under the path specified by the environment variable classpath or the system property java.class.path
  5. This class loader is the default loader in the program. Generally speaking, java application classes are loaded by it
  6. The class loader can be obtained through the ClassLoader#getSystemClassLoader() method

Four, user-defined class loader

  1. In the daily application development of java, the loading of classes is almost performed by the three types of loaders mentioned above. When necessary, we also need to customize the class loader to customize the way the class is loaded.
  2. Why do you need to customize the class loader?
    Isolate the loading class?
    Modify the loading method of the class.
    Extend the loading source to
    prevent source code leakage
  3. Implementation steps of user-defined class loader
    Insert picture description here

》》》Bloggers update their learning experience for a long time, recommend likes and follow! ! !
》》》If there is something wrong, please leave a message in the comment area, thank you! ! !

Guess you like

Origin blog.csdn.net/qq_41622739/article/details/105157523