4

I am running multiple tomcats on a Red Hat box and I would like to configure separate heap size for each of them (some instances use more memory).

Can I set the heap size min/max bt entering the following into the catalina.sh file:

CATALINA_OPTS="-Xms64m -Xmx256m"

Do I need add 'export'? i.e. export CATALINA_OPTS="-Xms64m -Xmx256m"

user353829
  • 1,244
  • 5
  • 25
  • 38

2 Answers2

13

Best practice is to put the setting of environment variables in a file named setenv.sh/.bat in the bin folder.

The catalina.sh script has logic to call into this script, if it exists.

The reason why this is recommended is because it makes setting of environment variables needed for your installation portable: you can easily copy setenv.sh to other Tomcat installations, you can upgrade Tomcat to a newer version (which might overwrite catalina.sh) but still have your existing setenv.sh.

An example on how to set the heap size inside setenv.sh:

export JAVA_OPTS='-Xmx784M` 
matt b
  • 138,234
  • 66
  • 282
  • 345
  • 13
    Note that `CATALINA_OPTS` is a better place than `JAVA_OPTS`. The former is only used when actually starting the Tomcat instance. `JAVA_OPTS` is also used to start JVMs that only interact with Tomcat (for example the JVM instance that is used to send the shutdown-message to a running Tomcat instance). Those JVMs usually don't need so much memory. – Joachim Sauer Jan 27 '10 at 12:02
  • Wow, great point Joachim - thanks for that. I'll have to go update all our scripts now :) – matt b Jan 27 '10 at 15:00
  • @mattb Do you mind updating your answer as well to fit with Joachim Sauer comment? – Mohamed Taher Alrefaie Aug 25 '14 at 10:17
1

If you add this to anything in the Tomcat installation, it will affect all instances run on that machine.

I think you want to set JAVA_OPTS separately, in separate scripts, which each then invoke Tomcat's startup script. The scripts can set different heap sizes. Yes, you need to export.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173