CATALINA_OPTS vs JAVA_OPTS - What is the difference?
JavaTomcatJvmTomcat6Java Problem Overview
I was trying to find out the difference between Apache Tomcat variables - CATALINA_OPTS
and JAVA_OPTS
in [SO][1] and surprised to see that there is no question/answer posted here yet. So I thought of sharing it here (with answer) after finding out the difference. Check the answer/difference below.
NOTE: At the time of this posting, we're running Apache Tomcat v6.0.10 with JDK 6u32 on CentOS5 64-bit arch.
[1]: http://stackoverflow.com "StackOverflow"
Java Solutions
Solution 1 - Java
There 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:
> [JAVA_OPTS]: (optional) Java runtime options used when the "start", "stop" or "run" > command is executed
and
> [CATALINA_OPTS]: (optional) Java runtime options > used when the "start" or "run" command is executed
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.
Source: [CATALINA_OPTS v JAVA_OPTS - What is the difference?][1]
[1]: http://www.wellho.net/mouth/2163_CATALINA-OPTS-v-JAVA-OPTS-What-is-the-difference-.html "CATALINA_OPTS v JAVA_OPTS - What is the difference?"
Solution 2 - Java
Durung shutdown, tomcat launches mutiple vm as explain in comment by @joao. If you are recording some data during tomcat shutdowm, use CATALINA_OPTS not JAVA_OPTS. A great example is when I want save the data during jacoco.exec, I should be using CATALINA_OPTS not JAVA_OPTS.
Solution 3 - Java
I'd like to add that JAVA_OPTS
and CATALINA_OPTS
are mutually complemental: If you define both environment variables, the content of both will be concatenated and passed to the start
and run
command - as explained by Gnanam above.
You can also refer to the original source of catalina.sh