<Loader delegate="true" /> tag in the tomcat configuration context

True, it means that tomcat will follow the delegate mechanism of the JVM, that is, when a WebAppClassLoader loads a class file, it will first submit it to the SharedClassLoader for loading. If the SharedClassLoader fails to load successfully, it will continue to delegate to its own parent class until the BootstarpClassLoader. , then finally loaded by WebAppClassLoader itself.
False means that this delegate mechanism will not be followed, that is, when WebAppClassLoader loads a class file, it will first try to load it by itself. If the loading fails, it will follow the inheritance chain and entrust the parent class to load in turn.

 

First of all, you need to understand the Classloader mechanism of the JVM (please google it for details).
In short, the JVM's classloader loading inheritance relationship is divided into BootstarpClassLoader --> ExtClassLoader --> SystemClassLoader, and the WebAppClassLoader of the application inherits from SystemClassLoader. When loading a specific class, it is generally delegated to the parent class ClassLoader first. When the ClassLoader cannot be loaded successfully, the subclass ClassLoader will try to load it again, which is the so-called delegate mechanism.

Second, Tomcat adds several inheritance levels to the JVM's ClassLoader mechanism.
SystemClassLoader --> CommonClassLoader -->(ServerClassLoader | SharedClassLoader --> WebAppClassLoader).
CommonClassLoader is used to load the class files under the common.loader configuration directory in ${CATALINA_HOME}/conf/catalina.properties, and is generally used to load files under ${CATALINA_HOME}/lib. The classes loaded by this loader are shared by the tomcat server and all webApps under tomcat.
ServerClassLoader is used to load the class files in the server.loader configuration directory in ${CATALINA_HOME}/conf/catalina.properties, and is generally used to load files under ${CATALINA_HOME}/server. The classes loaded by this loader are core classes unique to the tomcat server, and the WebApp under tomcat cannot be accessed.
SharedClassLoader is used to load class files in the shared.loader configuration directory in ${CATALINA_HOME}/conf/catalina.properties, and is generally used to load files in ${CATALINA_HOME}/shared. The classes loaded by this loader are shared by all webApps under tomcat.
WebAppClassLoader is used to load the /WEB-INF/class and /WEB-INF/lib class files of each WebApp application in the ${CATALINA_HOME}/webapps/ directory. Each WebApp corresponds to a WebAppClassLoader to load the classes it needs document.

Finally, talk about the meaning of the delegate configuration.
True, it means that tomcat will follow the delegate mechanism of the JVM, that is, when a WebAppClassLoader loads a class file, it will first submit it to the SharedClassLoader for loading. If the SharedClassLoader fails to load successfully, it will continue to delegate to its own parent class until the BootstarpClassLoader. , then finally loaded by WebAppClassLoader itself.
False means that this delegate mechanism will not be followed, that is, when WebAppClassLoader loads a class file, it will first try to load it by itself. If the loading fails, it will follow the inheritance chain and entrust the parent class to load in turn.

Let’s talk about the issues that need to be paid attention to when configuring as False: Once configured as False, if you define a java.lang.String in WebApp, the String class may override the String class in jdk. This may not be the result you want. In addition, for multiple WebApp public jar packages, you may share them in the ${CATALINA_HOME}/shared directory, but accidentally include a jar with the same name but a different version in the /WEB-INF/lib of the application. , which has the potential to cause a lot of weird problems.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326682968&siteId=291194637