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]