Use tomcat to set shared lib to share the same jar

Use tomcat to set shared lib to share the same jar

As more and more projects are deployed, more and more release packages will be deployed in Tomcat. In this way, it is inevitable that many identical jars will be loaded, occupying a large amount of permanent storage area memory. By setting shared lib, only one identical jar is loaded.

This has the following benefits:

1. Avoid loading the same jar in different projects to reduce the memory usage of the permanent storage area

2. Improve the startup speed of Tomcat because fewer duplicate jars are loaded

1. How to set up shared lib

Method 1:

Modify the catalina.properties file under the conf file and configure the path of shared.loader:

Configure the absolute path:

shared.loader="D:hs/develop/shared/lib","D:/hs/develop/shared/lib/*.jar"

After that place the same jar under the specified folder.

Or configure relative path:

shared.loader="${catalina.base}/shared/lib","${catalina.base}/shared/lib/*.jar"

Then create a new shared directory in the same directory as conf and put the same jar in lib

Method 2:

Modify the catalina.properties file under the conf file, configure the path of common.loader, and append the path of shared lib:

common.loader="${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar","${catalina.home}/lib/shared/*.jar"

Then create a shared directory in the lib folder and put the same jar in the shared directory

2. The difference between catalina.home and catalina.base

Under a tomcat, catalina.home and catalina.base point to the same location, which is the parent directory of bin and other directories.

If you want to install multiple Tomcat instances but do not want to install multiple software backups, you can use these two properties. In the tomcat directory, only the bin and lib directories are shared by multiple tomcat instances. Other directories such as conf, logs, temp, webapps, and work are independent backups of each Tomcat instance.

At this time they point to different locations:

catalina.home (installation directory): points to the location of public information, which is the parent directory of bin and lib.

catalina.base (working directory): points to the location of each Tomcat directory's private information, which is the parent directory of conf, logs, temp, webapps, and work.

3. Tomcat6 class loading mechanism

Commonclassloader :

Responsible for loading all classes and jar packages in the $CATALINA_HOME/common directory. For detailed configuration, refer to the common.loader configuration in the $CATALINA_HOME/conf/catalina.properties file. The classes loaded by this classloader are visible to the Server class loader and the Webapp class loader. The Commonclass loader is created when Tomcat starts, and its parent classloader is the System class loader.

Server classloader :

Responsible for loading Tomcat's core classes, all classes and jars in the $CATALINE_HOME/server directory, which can be specified by the server.loader configuration in catalina.propreties; it is created when Tomcat starts, and its parent loader is Commonclass loader;

Sharedclass loader :

Responsible for loading common classes of webapp, which can be specified by the user through the shared.loader property in the catalina.properties file; it is created when Tomcat starts, and its parentloader is also the Common class loader;

Webappclassloader :

It is only responsible for loading classes under WEB-INF/classes and WEB-INF/lib in each app; although its parentloader is a Shared class loader, its loading strategy is different from the default class loading mechanism;

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Solution to high CPU usage of Tomcat process
  • SpringBoot starts embedded Tomcat implementation steps
  • Tomcat breaks the parent delegation mechanism to achieve isolation of Web applications
  • A brief discussion on how Tomcat breaks the parent delegation mechanism
  • Fifteen Tomcat interview questions, a rare opportunity!

<<:  How to redirect to other pages in html page within two seconds

>>:  Detailed explanation of Vue's props configuration

Recommend

W3C Tutorial (2): W3C Programs

The W3C standardization process is divided into 7...

MySQL high availability solution MMM (MySQL multi-master replication manager)

1. Introduction to MMM: MMM stands for Multi-Mast...

MySQL Oracle and SQL Server paging query example analysis

Recently, I have done a simple study on the data ...

Detailed explanation of using grep command in Linux

Linux grep command The Linux grep command is used...

How to install lua-nginx-module module in Nginx

ngx_lua_module is an nginx http module that embed...

Nginx solves cross-domain issues and embeds third-party pages

Table of contents Preface difficulty Cross-domain...

Detailed installation tutorial for MySQL zip archive version (5.7.19)

1. Download the zip archive version from the offi...

An article to understand the advanced features of K8S

Table of contents K8S Advanced Features Advanced ...

A detailed introduction to the netstat command in Linux

Table of contents 1. Introduction 2. Output Infor...

CSS to achieve zoom in and out close button (example code)

This effect is most common on our browser page. L...