tomcat share the same set of shared lib jar

In more and more projects, when deployed in tomcat release package will be more and more, so it is inevitable that many of the same jar will be loaded, take up a lot of memory area permanent existence, controlled by the same set of shared lib just load a jar, so has the following advantages:

1, to avoid different project to load the same jar, reduce the memory footprint of the permanent existence region

2, improve the startup speed tomcat, because less loaded with many repetitive jar

First, how to set up shared lib

method one:

Catalina.properties modify files in the conf files, configuration path shared.loader of:

Configuration absolute path:

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

After the same jar into the specified folder.

Or the relative path configuration:

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

After the conf directory and create a new shared directory with the same jar in the lib

Second way:

catalina.properties file modification conf files, configuration common.loader path, the path of the additional shared lib:

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

After create a shared directory in the lib folder, and the same jar on the shared directory

Two and distinguishing, catalina.home and the catalina.base

In a tomcat, catalina.home catalina.base and point to the same location, i.e., the parent directory like directory bin.

If these two attributes can be used to install multiple instances of Tomcat do not want to install more software backup directory under the tomcat bin and lib directories are only more public tomcat example, other directory conf, logs, temp, webapps and work each Tomcat instance is its own independent backups. Then they point to a different location:

  • catalina.home (installation directory): points to the location information of the public, is the parent of the bin and lib directory.
  • catalina.base (working directory): points to the location of each Tomcat directory private information, that is, conf, logs, temp, webapps and work of the parent directory.

Three, tomcat6 class loading mechanism

Commonclassloader : responsible for loading all the classes and packages jar under $ CATALINA_HOME / common directory, with reference to the detailed configuration common.loader configured $ CATALINA_HOME / conf / catalina.properties file; the classloader loaded class and for the Server class loader Webapp class loader are visible; Commonclass loader created when Tomcat starts, its parent classloader is System class loader;

ClassLoader Server : Tomcat class loader is responsible for the core of all the classes located under $ CATALINE_HOME / server directory and jar, by catalina.propreties in server.loader configuration specifies; it is created when Tomcat starts, its parent loader is Commonclass loader;

Loader Sharedclass : webapp common class is responsible for loading, can be specified by the user catalina.properties shared.loader attribute file; it is created when starting Tomcat, which is parentloader Common class loader;

WebappClassLoader : it is only responsible for loading each app in the WEB-INF / classes and classes under WEB-INF / lib; although parentloader is Shared class loader, but its strategy and load the default class loading mechanism is not the same;

Guess you like

Origin www.cnblogs.com/kingsonfu/p/11360383.html