CATALINA_OPTS v JAVA_OPTS - What is the difference?
Archive - Originally posted on "The Horse's Mouth" - 2009-05-09 16:52:19 - Graham EllisThere are two environment variables - CATALINA_OPTS and JAVA_OPTS - which are both used in the catalina.sh startup and shutdown script for Tomcat. They are described in comments within that file as:
(optional) Java runtime options used when the "start", "stop" or "run" command is executed [JAVA_OPTS]
and
(optional) Java runtime options used when the "start" or "run" command is executed [CATALINA_OPTS]
So why are there two different variables? And what's the difference?
Firstly, anything specified in EITHER variable is passed, identically, to the command that starts up Tomcat - the "start" or "run" command - but only values set in JAVA_OPTS are passed to the "stop" command. That probably doesn't make any difference to how Tomcat runs in practise as it only effects the end of a run, not the start.
The second difference is more subtle. Other applications may also use JAVA_OPTS, but only Tomcat will use CATALINA_OPTS. So if you're setting environment variables for use only by Tomcat, you'll be best advised to use CATALINA_OPTS, whereas if you're setting environment variables to be used by other java applications as well, such as by JBoss, you should put your settings in JAVA_OPTS.
"OK - so that's the difference. Give me some examples of what can go in there!"
You can increase heap memory available to the JVM - see here
You can open remote monitoring ports so that Jconsole on another system can watch how your Tomcat is running - see here
You can add in a -server to switch from the client (quicker start, slower running) JVM to the server (slower starting, quicker running) JVM.
You can increase java thread stack size using the -Xss option (same way to specify amount of memory as in -Xms and -Xmx as described in the "increase heap memory" link above.