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!

Advertisements

One response to this post.

  1. Posted by kai on August 31, 2011 at 9:18 AM

    Your blog post helped me. Thank you for sharing!

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: