Thanks for the advice Tim. I noticed that you cant use this for
java 1.6. I had to do a little messing around, but I finally managed to get the memory dumps I needed. I've put together a rough HowTo for those that are interested;
For java 1.5 use:
1) Find the following line of code in your catalina.sh file;
elif [ "$1" = "start" ] ; then
2) Underneath this line add the following;
JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnCtrlBreak -Dcatalina.ext.dirs=$CATALINA_HOME/shared/lib:$CATALINA_HOME/common/lib -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
Specifically the command -XX:+HeapDumpOnCtrlBreak will generate the heap dump file.
3) Start up tomcat as usual
4) After a few minutes get the process id of the tomcat process
ps ux | grep apache
look for anything in the line that says tomcat_version….
5) Use this process id to send a signal to the process with the following code
kill -3 <pid>
6) This will create a new file in the bin directory of you tomcat root installation directory with the .hprof.date.time extension. Remove the date.time extension and you can use this file with memory monitoring applications like eclipse based memory analyser
For java 1.6 use: jmap or jconsole
-both of these are tools that come bundled with package. They located in JAVA_HOME/bin.
jmap
1) Find the pid of the process
ps ux | grep [java/apache]
2) Use the following command to invoke jmap
$JAVA_HOME/bin/jmap -dump:live,file=heap.dump.out,format=b <pid>
jconsole
1) Find the following line of code in your catalina.sh file;
elif [ "$1" = "start" ] ; then
2) Underneath this line add the following;
JAVA_OPTS="$JAVA_OPTS -Dcatalina.ext.dirs=$CATALINA_HOME/shared/lib:$CATALINA_HOME/common/lib -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
3) Open jconsole (just type jconsole)
4) Go to the mbeans tab
5) In the left hand tree structure look for the following folder; com.sun.management. Expand and click on HotSpotDiagnostic
6) In the right hand window click on operations. There should be an option to dump the heap memory in the tomcatHome/bin directory