• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Tomcat Heap Dump - SOLVED

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Saloon Keeper
Posts: 25477
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Hot dog! An advertiser loves us THIS much:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic