Tomcat - How to limit the maximum memory Tomcat wi

2020-02-24 12:29发布

问题:

I am running Tomcat on a small VPS (256MB/512MB) and I want to explicitly limit the amount of memory Tomcat uses.

I understand that I can configure this somehow by passing in the java maximum heap and initial heap size arguments;

-Xmx256m
-Xms128m

But I can't find where to put this in the configuration of Tomcat 6 on Ubuntu.

Thanks in advance,

Gav

回答1:

Set JAVA_OPTS in your init script,

 export JAVA_OPTS="-Djava.awt.headless=true -server -Xms48m -Xmx1024M -XX:MaxPermSize=512m"


回答2:

On Ubuntu, the correct way to customize Tomcat variables is by editing the file

/etc/default/tomcat5.5

(or /etc/default/tomcat6 if you have a newer version running)

Inside that file, set the JAVA_OPTS variable as described in the other replies here, for example

JAVA_OPTS="-Xmx512m"

to set a maximum memory of 512 MB.



回答3:

You can add this to the JAVA_OPTS variable in the bin/catalina.sh startup script.

JAVA_OPTS="-Xms128m -Xmx256m"