Archive for July 14th, 2009

How to enable verbose GC in tomcat

The Problem

Where do I put the “Enable verbose GC” setting in Tomcat? Is there a switch or something?

The Fix

The file that you should use to enable verbose gc for Tomcat ( Or for the JVM that Tomcat is running in ) is $TOMCAT_HOME/bin/setenv.sh/.bat. This file might not exist in your install so when you create the file it will be loaded from the $TOMCAT_HOME/bin/catalina.sh/.bat script. Here is the snip from around line 110 in catalina.sh

if [ -r "$CATALINA_BASE"/bin/setenv.sh ]; then
 . "$CATALINA_BASE"/bin/setenv.sh
elif [ -r "$CATALINA_HOME"/bin/setenv.sh ]; then
 . "$CATALINA_HOME"/bin/setenv.sh
fi

Here is an example setenv.sh file with verbose gc enabled, look at the bold part:

JAVA_OPTS="-Xms256m -Xmx512m \
  -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -verbose:gc -Xloggc:/tmp/gc.log"

CATALINA_OPTS="-Dappserver.home=$CATALINA_HOME \
 -Djava.library.path=/usr/local/apr/lib \
 -Djava.awt.headless=true \
 -Dcom.sun.management.jmxremote \
 -Dcom.sun.management.jmxremote.port=8050 \
 -Dcom.sun.management.jmxremote.ssl=false \
 -Dcom.sun.management.jmxremote.authenticate=false"

export JAVA_OPTS CATALINA_OPTS

Now restart tomcat and you are done!