In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the structure and storage directory of Tomcat class loading". In daily operation, I believe many people have doubts about the structure and storage directory of Tomcat class loading. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "Tomcat class loading framework and storage directory". Next, please follow the editor to study!
1. Problems to be solved in Web server
A fully functional Web server needs to solve the following problems:
(1) the Java class libraries used by two Web programs on the same server are independently isolated from each other: one class library cannot be used by multiple programs with only one copy on the same server.
(2) the Java class libraries used by two Web applications on the same server can be shared: if not, the Method Area inside the virtual machine may be overinflated.
(3) the class library of the server and the class library of the Web application should be isolated from each other and do not affect each other (that is, the server does not accept the influence of Web programs): many servers may be implemented with Java, so they naturally have to use some class libraries that only belong to themselves.
(4) Hot replacement (HotSwap) that supports JSP: most major servers (except WebLogic) do not need to restart the server to modify the JSP file.
Just imagine, if any of the above 4 points are not satisfied, especially points (1)-(3), then the entire Java Web server is "chaotic" or imperfect.
2. Put Tomcat inventory in the catalogue.
Since you want to meet the above four basic requirements, when deploying a Web application, a Classpath path directory cannot meet the requirements. Usually, multiple Classpath (usually named after classes/lib) path directories are provided, and there is a corresponding custom class loader in the directory to load the Java classes inside. There are three groups of directories in Tomcat: / common/*, / server/*, / shared/*
However, it is worth emphasizing that these three sets of directories no longer exist after Tomcat 6.x, there is only a total / lib directory, and the rest need to be configured separately when needed to enter the configuration file. So the directory described here may not be found in the tomcat installation directory, but the intention is the same.
(1) / common/*: is actually created in the / common/lib/ directory, and the class libraries that can be shared by Tomcat with all Web applications are in it.
But the / common/lib/ directory was abandoned after Tomcat 6, and now the default is under / lib/, which actually merges / common, / server, and / shared into one / lib directory by default. If you do not meet the specific business needs, you can set up server.loader and shared.loader in conf/catalina.properties. When you open conf/catalina.properties, you can see that either ${catalina.base} or "${catalina.home} will go to the / lib/ directory and specify the loader to load.
CATALINA_BASE: the location of instance configuration, that is, multiple instances can be configured in a tomcat, and the instance has its own configuration.
CATALINA_HOME: is the tomcat installation location
Common.loader, server.loader, shared.loade: indicates that tomcat specifies three custom loaders.
(2) / server/*: is actually created in the / server/lib directory and can only be used by Tomcat.
(3) / shared/*: was actually created as the / shared/lib directory, which can be shared by all Web applications, but is not visible to Tomcat.
(4) / webapps (wtswebapps) / project/WEB-INF/*: is actually / WebApp/project/WEB-INF/lib, which is the exclusive class library of Project.
3. Tomcat custom loader
Tomcat custom class loaders mainly include: ComnonClassLoader, CatalinaClassLoader, SharedClassLoader and WebAppClassLoader class loaders.
(1) ComnonClassLoader: loads the classes under the / common/* directory, but as you can see from the above, all the specified loads are configured in Catalina.properties.
(2) CatalinaClassLoader: load the classes in the / server/* directory, just as you now specify the configuration in Catalina.properties.
(3) SharedClassLoader: load the classes in the / shared/* directory, just as you now specify the configuration in Catalina.properties.
(4) WebAppClassLoader: load the classes in the project lib under the / webapps (wtswebapps) / project/WEB-INF/* directory.
The delegate relationship (the class loading mechanism of the Tomcat server) combined with the previous three classloaders (BootstrapClassLoader, ExtensionClassLoader, ApplicationLoader) and the four custom loaders of Tomcat is as follows:
(note: where JasperLoader is the Jsp class loader, and the JSP file is compiled into a Class file, which needs to be loaded)
From this diagram, we can get the following two points:
(1) CatalinaClassLoader and SharedClassLoader are isolated from each other.
(2) WebAppClassLoader can use SharedClassLoader to load classes, WebAppClassLoader can replace JspClassLoader to load classes, and classes loaded by CommonClassLoader can be used by CatalinaClassLoader and SharedClassLoader.
At the same time, we should pay attention to the following two points:
JspClassLoader can only load the Class file compiled from this JSP file. When the JSP file is modified, the current JspClassLoader instance will be replaced, and then a new JspClassLoader instance will be re-established, which is the internal implementation of HotSwap.
Different WebAppClassLoader are isolated from each other.
For version 6.x of Tomcat, SharedClassLoader and CatalinaClassLoader instances can be used only if shared.loader and server.loader are configured in conf/catalina.properties, otherwise the instance of ComnonClassLoader will be used by default
If the default settings do not meet your needs, you can restart the Tomcat 5.x loader architecture by modifying the shared.loader and server.loader in the configuration file.
At this point, the study on the "Tomcat class loading architecture and storage directory" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.