Tomcat Class Loader

Source: Internet
Author: User
Conversion from: Structure of the http://www.huihoo.org/apache/tomcat/heavyz/03-classloader.html1-Tomcat Class Loader

Tomcat server constructs a classloader tree at startup to ensure that the class library of the module is private.
The classloader structure of Tomcat server is as follows:
Where:
-Bootstrap-load the built-in JVM class and $ java_home/JRE/lib/EXT/*. Jar
-System-load $ classpath/*. Class
-Common-load $ catalina_home/common/.... They are visible to Tomcat and all web apps.
-Catalina-load $ catalina_home/Server/.... They are only visible to Tomcat and not to all web apps.
-Shared-load $ catalina_home/shared/.... They are only visible to all web apps and Tomcat (and do not need to see them)
-Webapp? -Load contextbase? /WEB-INF/... they are only visible to the web app

+ --------------------------- + | Bootstrap | system | common | // | Catalina shared | // | webapp1 webapp2 | + ----------------------- +

 

 

2-Working Principle of classloader

Each running thread has a member contextclassloader, which is used to dynamically load other classes at runtime.
The default contextclassloader is systemclassloader.ProgramDuring execution, you can use classes in the JVM, $ java_home/JRE/lib/EXT/, and classes in $ classpath /.
AvailableThread. currentthread (). setcontextclassloader (...);Change the contextclassloader of the current thread to change its loading behavior.

Classloader is organized into a tree. The general working principle is:
1) The thread needs to use a class, so the contextclassloader is requested to load the class.
2) contextclassloader requests its parent classloader to complete the load request.
3) if the parent classloader cannot load the class, contextclassloader tries to load the class by itself.

Note:: Webapp? The working principle of classloader is slightly different from the above:
It first tries to load the class itself (in contextbase? /WEB-INF/... to load the class), if not loaded, then request the parent classloader to complete

Therefore, you can obtain the following information:
-For a web app thread, is its contextclassloader webapp? Classloader
-For the Tomcat server thread, its contextclassloader is catalinaclassloader.

3-some original Code Analysis

3.1-ORG/Apache/Catalina/startup/Bootstrap. Java

Starting Point of the Tomcat server thread
Construct the classloader tree and set contextclassloader of the Tomcat server thread to catalinaloader.
Load several classes and transfer them to the org. Apache. Catalina. startup. Catalina class.

[View code]

3.2-ORG/Apache/Catalina/startup/classloaderfactory. Java

Create and return the standardclassloader instance according to the settings

[View code]

3.3-ORG/Apache/Catalina/loader/standardclassloader. Java

Class Loader

3.4-ORG/Apache/Catalina/startup/securityclassload. Java

This class contains only one static method to load some classes for catalinaloader.

[View code]

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.