Using JMap, JHat, and JConsole to monitor the app

First make sure there is a file named setenv.sh in the tomcat/bin dir. Here is sample text for the file:

JAVA_OPTS="-server -Xms256m -Xmx1024m -XX:MaxPermSize=256m -Djava.awt.headless=true -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9009 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

If you don't have this file, you'll probably have trouble running jmap.

jMap command:

jmap -dump:format=b,file=heap.bin 6496

6496 is the process id

If this does not work, see if you are already using the jmxremote.port. Also see if .jmxremote=true. Lastly, check /tmp to see what user the hsperfdata process thinks that tomcat is running in. If the directory is called hsperfdata_root, and if the current tomcat process id is in a file within that folder, then tomcat is running as root. If it is not running, maybe tomcat is running as tomcat. You must run jmap as the same user that tomcat is running.

If that does not work, you probably don't have the setenv.sh file. You may force the dump with the -F switch:

jmap -F -dump:format=b,file=heap.bin 6496

A dump that is created using the -F switch will not display as much in information as without it; therefore, it is recommended to make sure you have setenv.sh.

JHat command:

C:\temp>jhat -J-mx768m -stack false heap.bin
Reading from heap.bin...
Dump file created Wed Sep 05 15:55:04 CAT 2007
Snapshot read, resolving...
Resolving 591288 objects...
Chasing references, expect 118 dots............
Eliminating duplicate references...............
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.

To monitor in JConsole, add the following to your java properties in tomcat

-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=8086
-Dcom.sun.management.jmxremote.ssl=false

Then, open Jconsole and enter remote process, then localhost:8086