问题
How can I add custom memory parameters to tomcat8
service?
I created the following file:
-rwxr-xr-x 1 root root 211 Jun 13 10:51 setenv.sh
Content:
#! /bin/sh
export CATALINA_OPTS="$CATALINA_OPTS -Xmx1024m"
export CATALINA_OPTS="$CATALINA_OPTS -Xms512m"
After restart:
ps aux | grep java
Result: I cannot see my defined memory options. Only:
... -Xmx128m
But why? How can I check if or why setenv.sh is loaded correctly?
回答1:
Solution: I took the wrong directory. setenv.sh must be placed here:
/usr/share/tomcat8/bin
回答2:
Since the question mentions tomcat8
I assume this refers to the Debian package. I was looking for a Debian-friendly solution to this problem and just discovered another way to add arbitrary system properties to Tomcat on startup.
The standard Debian package for Tomcat also creates a default configuration file under:
/etc/default/tomcatX
(X is the Tomcat version number).
System properties and other JVM startup parameters can be added to JAVA_OPTS
:
# You may pass JVM startup parameters to Java here. If unset, the default
# options will be: -Djava.awt.headless=true -XX:+UseConcMarkSweepGC
#
# Use "-XX:+UseConcMarkSweepGC" to enable the CMS garbage collector (improved
# response time). If you use that option and you run Tomcat on a machine with
# exactly one CPU chip that contains one or two cores, you should also add
# the "-XX:+CMSIncrementalMode" option.
JAVA_OPTS="-Djava.awt.headless=true -XX:+UseConcMarkSweepGC"
This is by the way also the configuration file where a different JVM can be specified, in case multiple are installed on the system, or where the user running Tomcat can be changed.
来源:https://stackoverflow.com/questions/44517017/how-to-configure-setenv-sh-for-tomcat8