JAVA_OPTS...

I am trying to increase the memory for my JVM heap and permgen on my Tomcat 6 server. I was getting out of memory errors whenever I tried to run a second webapp. I am very new at this, but to my understanding the method is to put your JVM startup switch settings in the JAVA_OPTS variable. This is my switch:

JAVA_OPTS="-Xms128m -Xmx512m -XX:MaxPermSize=512m"

I put this it /etc/bash.bashrc. On startup I still get


...
java.lang.OutOfMemoryError: PermGen space
...
java.lang.OutOfMemoryError: PermGen space
...

These webapps both run fine on their own in Tomcat, but not together.

So my questions are:

  1. Is my JAVA_OPTS in the correct place?
  2. How can I tell how much memory the JVM is actually using?

Would appreciate any ideas!

Go to the bin directory where tomcat is installed and do the following:

  1. cp catalina.sh catalina.sh-today’s-date

Add number 2 in your catalina.sh

  1. CATALINA_OPTS="-Xms128m -Xmx128m"

  2. bounce tomcat

// Note: assuming your local machine is running
Tomcat on port 8080
4. http://localhost:8080/manager/status

Regards,
Someone316

Although that works, it’s a dirty shortcut :-).

Your change to /etc/bash.bashrc should work if you add

export CATALINA_OPTS="..."

Without “export” the variable will not be visible. If you, or any other user, are starting/stopping tomcat then ~/.bashrc is a better place in my opinion.

Just one more note, you can “quickly” test a setup by running tomcat with the command

$> CATALINA_OPTS="-Xms128m -Xmx512m -XX:MaxPermSize=512m" catalina.sh run

or

$> export CATALINA_OPTS="-Xms128m -Xmx512m -XX:MaxPermSize=512m"
$> catalina.sh run

Really, please explain? How would this work with multiple tomcat instances running on the same host with different CATALINA_OPTS? Making the changes in catalina.sh seems valid, this way you isolate it to the given tomcat instance.

Regards,
Someone316

Its just my general policy of not customizing installed files.

Anyway, tomcat provides many options to override settings without editing the default files. Look for the CATALINA_BASE property. It allows you to have a single installation and multiple configurations (server.xml, webapps, etc).

$> CATALINA_BASE="path1" CATALINA_OPTS="-Xmx128m" CATALINA_PID="instance1.pid" catalina.sh start
$> CATALINA_BASE="path2" CATALINA_OPTS="-Ddebug ..." CATALINA_PID="instance2.pid" catalina.sh start

Thanks for the responses, guys! Will post later…