This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat Heap Dump - SOLVED

 
Jaz Chana
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I'm using tomcat version 5.5 with jdk 5. I would like to create a heap dump file while the server is running so that I can use this in some monitoring application. How would I do this?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17626
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to start the Tomcat server with the profiling options you want to be used. I believe that the JAVA_OPTIONS environment variable can be used to pass them into the catalina startup script.

To actually get a snapshot taken, you fire a signal to the Tomcat server. In Linux, this can be done using the "kill" command. If you send the right signal "kill" won't actually kill the app, it simply triggers a JVM snapshot. You can do this as many times as you like (they will be appended).

I'd be more specific, but I'd have to go back and RTFM. I've forgotten the exact details.
 
Jaz Chana
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Sravan revuru
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can you tell me the same process for Windows - tomcat version....
windows 7
Tocat 6.0
jdk 1.5

wat shoud i change in catalina.bat


thanks,
Sravan
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic