About Classloader study notes

 1) class loading process is kind of how?
① Load: according to particular needs, select the appropriate loader (Bootstrap ClassLoader not directly acquire, Extension ClassLoader, systems, custom) to acquire the control byte stream, a Class object is instantiated as a data access entry.
② connection (validation, preparation, analytical) :( the JVM)
A. Verification, sources in the loading phase is not guaranteed by the byte stream is a pure java code is compiled over, it could also be downloaded on the network, others to file , zip bag and the like, so to be verified (verification file format, metadata validation, bytecode verification, verification of symbolic references);
. preparation B,
c parsing constant pool will replace references to sign a direct reference;.
③ initialization: the real implementation of Java code that is executed only once. Here also through the class constructor, the specified initial value assigned to static variables. (Note: At this time, the above initial value setting different class variable in the preparation phase);
 2) two different class loaders loading the same class, how to distinguish and isolate?
Parents delegate mechanism
observed loadClass ClassLoader () method:
public Class the loadClass (String name) throws a ClassNotFoundException {<?>
        Return the loadClass (name, to false);
    }
protected the loadClass the synchronized Class (String name, Boolean Resolve) <?>
    throws ClassNotFoundException
    {
       Class c = findLoadedClass(name);
            if (c == null) {
        try {
            if (parent != null) {
            c = parent.loadClass(name, false);
        } else {
            c = findBootstrapClassOrNull(name);
        }
        } catch (ClassNotFoundException e) {
            }
            if (c == null) {
            c = findClass(name);
        }
    }
            if (resolve) {
            resolveClass(c);
    }
    return c;
}
Draw: When a request to load the class, first check has been loaded before, after the judgment is not loaded, load the first to complete the task entrusted to the parent class loader loads the task, so all load requests should be sent to the boot class loader Of these, only the parent loader can not complete this task load throw an exception, but only to load their own.
And because the relationship between the respective load is a combined, have their respective division, different instances of the class loader loads, it will have two different classes in the process area, is not visible to each other, and produce different stack Class instance. During the delegation request, each level must be above class loader operation, to achieve level appointment.
Since it is ensured that the same name in different ClassLoader loaded object class are of different types, and the conversion can not be compatible with each other therebetween. The same type of class loader to load different objects out of the class is not the same class. To achieve the distinction and isolation effect.

Guess you like

Origin www.cnblogs.com/1693977889zz/p/11279837.html