简体   繁体   English

如何在Tomcat中设置自定义垃圾收集器算法

[英]How to Set a Custom Garbage Collector Algorithm in Tomcat

I want to set a custom garbage collector algorithm for my java application[war] which is running on top of tomcat. 我想为运行在tomcat之上的java应用程序[war]设置自定义垃圾收集器算法。 I am using java8 and the default garbage collector is parallelGC. 我正在使用java8,默认的垃圾回收器是parallelGC。 I want to use G1GC or CMS GC instead of this. 我想使用G1GC或CMS GC代替它。

java -XX:+UseG1GC -jar Application.java

A Jar application can be executed with the above command. 可以使用上述命令执行Jar应用程序。 But I want to know how we can configure this in tomcat/ with a war application? 但是我想知道我们如何使用war应用程序在tomcat /中配置它?

我认为您可以在variables.conf文件中做到这一点,可以在其中添加如下代码:

-XX:+UseG1GC

Found an answer, I will post it here for the community usage 找到了答案,我将在这里发布以供社区使用

When we need to set a custom GC for tomcat, we can pass the GC type as a parameter to the CATALINA_OPTS env variable. 当需要为tomcat设置自定义GC时,可以将GC类型作为参数传递给CATALINA_OPTS env变量。

export CATALINA_OPTS = "-XX:+UseG1GC"

You can set this env variable in setenv.sh file(tomcat/bin/setenv.sh) or jvmsettings.sh file(/etc/profile.d/jvmsettings.sh). 您可以在setenv.sh文件(tomcat / bin / setenv.sh)或jvmsettings.sh文件(/etc/profile.d/jvmsettings.sh)中设置此env变量。 Addition to the GC type you can pass other jvm parameters to the same command 除了GC类型,您还可以将其他jvm参数传递给同一命令

export CATALINA_OPTS="-Xms4096M -Xmx7168M -XX:+UseG1GC -XX:+PrintGCDetails -Xloggc:/settings/logs/gc.log"

After completing the configurations, restart the tomcat server. 完成配置后,重新启动tomcat服务器。 Then execute the following command to get the currently using GC type 然后执行以下命令以获取当前使用的GC类型

jmap -heap <process_id>

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM