Saturday, July 8, 2017

JVM Classloader


 Parent Delegation 

Class loading sequence in JVM follow parent  delegation = inverse DNS sequence. when class receive the loading request, it dones't load the class but looking for his parent classloader to load it . And the parent classloader looks for the grandparent classloader to load the class. So the sequence is inversed compared with the DNS parsing sequence.

Self-defined classloader



public class FileSystemClassLoader extends ClassLoader { // extends ClassLoader
 
 protected Class<?> findClass(String name) { // rewrite findClass
        byte[] classData = new byte[11];   // implementation..
        return defineClass(name, classData, 0, classData.length); // return the implemented Class
    }
}

// ClassLoader will triger its own loadClass() method then call  findLoadedClass()to check whether this class is loaded by parent
// if not parent classloader will trigger its loadClass() to load, if failed, it will trigger findClass() to load

No comments:

Post a Comment

Add Loading Spinner for web request.

when web page is busily loading. normally we need to add a spinner for the user to kill their waiting impatience. Here, 2 steps we need to d...