Tomcat-Orthodox Class Loader architecture, tomcat-loading Architecture

Source: Internet
Author: User

Tomcat-Orthodox Class Loader architecture, tomcat-loading Architecture

Mainstream Java Web servers include tomcat, Jetty, WebLogic, WebSphere, etc. These servers all implement their own defined loaders (generally one or more ), because a fully functional server needs to solve the following problems:

  • The Java class libraries used by two Web applications deployed on the same server can be isolated from each other, which is the most basic requirement. two different applications may depend on different versions of the same third-party class library. A Class Library cannot have only one copy in one server. The server should ensure that the class libraries of the two applications can be used independently of each other.
  • Java class libraries used by two Web applications deployed on the same server can be shared with each other. This requirement is also common. If Java class libraries cannot be shared, the Virtual Machine Method Area is prone to the risk of excessive expansion.
  • The server should be protected against the deployed Web applications as much as possible. currently, many mainstream Java Web servers are developed using the Java language, so the server itself also has class library dependencies. Generally, based on security considerations, the class library used by the server should be independent from the class library used by the application.
  • Most servers that support JSP must support HotSwap (Hot Swap)

Due to the above problems, when deploying a Web application, if you only use a single ClassPath, therefore, various Web servers provide multiple ClassPath paths for users to have third-party class libraries. These paths are generally named in lib and classes and placed in class libraries in different paths, different access scopes

And the service object. tomcat server divides the user class library structure and class loading description as follows:

In the tomcat directory structure, there are three groups of directories:/common/*,/server/*,/shared/*, which can be used to store class libraries, there are also Web application directory/WEB-INF/* A total of four groups, put the Java class library in these directories meaning and the difference is as follows:

  • Placed in the/common/* Directory: These class libraries can be used by tomcat and all web applications.
  • Placed in the/server/* Directory: These class libraries can be used by tomcat, and all web applications are invisible.
  • Placed in the/shared/* Directory: These class libraries can be used by all web applications, but are invisible to tomcat itself.
  • Placed in the/WEB-INF/* Directory: These class libraries are used only for the current web application and are invisible to tomcat and other web Applications

To support the preceding directory structure and load and isolate class libraries in the directory, Tomcat defines multiple class loaders for implementation, these class loaders are implemented according to the classic parent-child Delegation Model. Their relationships are as follows:

The main class loaders include CommonClassLoader, CatalinaClassLoader, SharedClassLoader, and WebappClassLoader. They load/common/*,/server/*, respectively /*, /shared/* And/WEB-INF/* Directory class library, where WebApp loader and JSP Class Loader instance usually have multiple

Each web application corresponds to a webapp class loader, and each JSP file corresponds to a JSP class loader.


Through the relationship diagram above, we can see that all classes that can be loaded by CommonClassLoader can be used by CatalinaClassLoader and SharedClassLoader. classes that can be loaded by CatalinaClassLoader and SharedClassLoader are isolated from each other. webappclasslo

Classes that can be loaded, but each WebAppClassLoader instance is isolated from each other. The loading scope of JasperLoader is only the Class compiled by the JSP. It is used to discard the Class: when the server detects that the JSP file is modified, it replaces the current JasperClassLoader instance and creates another

New JSP class loader to implement the HotSwap function of JSP files

 

References: deep understanding of Java virtual machines

 

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.