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

Page Refactoring Skills - Content

Enough of small talk <br />Based on the lar...

Clever use of webkit-box-reflect to achieve various dynamic effects (summary)

In an article a long time ago, I talked about the...

A simple method to modify the size of Nginx uploaded files

Original link: https://vien.tech/article/138 Pref...

A brief analysis of controlled and uncontrolled components in React

Table of contents Uncontrolled components Control...

A simple way to achieve scrolling effect with HTML tag marquee (must read)

The automatic scrolling effect of the page can be...

Tomcat common exceptions and solution code examples

The company project was developed in Java and the...

How to fix abnormal startup of mysql5.7.21

A colleague reported that a MySQL instance could ...

JS thoroughly understands GMT and UTC time zones

Table of contents Preface 1. GMT What is GMT Hist...

A brief discussion on the problem of forgotten mysql password and login error

If you forget your MySQL login password, the solu...

Detailed explanation of the principle of Docker image layering

Base image The base image has two meanings: Does ...

Vue2 cube-ui time selector detailed explanation

Table of contents Preface 1. Demand and Effect ne...

How to start a Vue.js project

Table of contents 1. Node.js and Vue 2. Run the f...

How to install ELK in Docker and implement JSON format log analysis

What is ELK? ELK is a complete set of log collect...