Java class loading process

Java class loading is divided into the following three steps

  1. Load the .class file into memory
  2. Bytecode verification, Class data structure analysis, memory allocation
  3. Static attributes and initial assignment, execution of static blocks

Note: When loading class files, only class variables, static initialization blocks, and static member variables are initialized. The methods in the class will only be loaded into the heap and will not be initialized.

Ways to load classes

Java uses ClassLoader to load classes into memory. Java has the following three ClassLoader

  1. Bootstrap ClassLoader
    This is the top classloader and mainly loads the classes required by the JVM for its own work
  2. ExtClassLoader
    this user loads the class under the path of "java.ext.dirs"
  3. AppClassLoader
    is an ordinary classloader used to load classes in the classpath path

Java ClassLoader is to ensure that each class can only be loaded once by the level loading mechanism. When each ClassLoader loads a class, it will first call the superior ClassLoader to determine whether it has been loaded. If it is not loaded, and there should be no superior classLoader loaded, then this class will be loaded into the JVM by the current ClassLoader.

Note: jvm uses the full class name of Class + ClassLoader instance to load this class to determine whether this class already exists. In other words, the same class is loaded by different ClassLoader instances (different instances of the same ClassLoader class), and the JVM will think that these are two different classes.

Hot deployment

Published 190 original articles · 19 praises · 200,000+ views

Guess you like

Origin blog.csdn.net/zengchenacmer/article/details/77692431