Jetty Study Notes-jetty classloader

Source: Internet
Author: User
Document directory
  • Classloader is mainly responsible for the work
  • Classloader's find Class Method
  • Classloader category
  • Context classloader
  • If childfirst is used, the search path is:

Java classloader Review

Take Sun JDK as an Example

Classloader is mainly responsible for the work
  • Find class: Find the class
  • Links class: class and File Link
  • Define class: converts a binary file to an instance of the class.
Classloader's find Class Method
  1. Findloadedclass: First, check whether it has been loaded by the current classloader.
  2. Parent. loadclass: Call the parent loader to load data. If there is no parent loader, call the native findbootstrapclass * method to obtain the data.
  3. Findclass: If none of the above is found, call the current findclass
Class c = findLoadedClass(name);                if (c == null) {                    try {                        if (parent != null) {                            c = parent.loadClass(name, false);                        } else {                            c = findBootstrapClass0(name);                        }                    } catch (ClassNotFoundException e) {                        // If still not found, then invoke findClass in order                        // to find the class.                        c = findClass(name);                    }                }

Classloader category

  • Bootstraploader: Native. It is started after JVM is started. It is responsible for loading the core lib/class (including the following two classloader) in JRE ).
  • Extclassloader: loaded by bootstraploader, responsible for loading the ext package in JRE, parent = NULL
  • Appclassloader: loaded by bootstraploader, responsible for loading classes in classpath, parent = extclassloader
  • Userclassloader: Custom classloader, specifying the resource location through URL
Context classloader

Implement the requirement for parent classloader to load the class in the sub-classloader URL
Jetty classloader

Webappclassloader. loadclass:

1. Find the existing class

Class<?> c= findLoadedClass(name);

2. If parentfirst or system_class is not server_class, parentfirst is used.

if (c == null && _parent!=null && (_context.isParentLoaderPriority() || system_class) && !server_class)        {            tried_parent= true;            try            {                c= _parent.loadClass(name);                if (Log.isDebugEnabled())                    Log.debug("loaded " + c);            }            catch (ClassNotFoundException e)            {                ex= e;            }        }

3. Otherwise, the current findclass is called.

 if (c == null)        {            try            {                c= this.findClass(name);            }            catch (ClassNotFoundException e)            {                ex= e;            }        }

4. Find the current Trojan and find the parent.

 if (c == null && _parent!=null && !tried_parent && !server_class )            c= _parent.loadClass(name);

5. Resolve

if (resolve)            resolveClass(c);

If childfirst is used, the search path is:

Webappclassloader --> bootstraploader --> extclassloader --> appclassloader

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.