views:

302

answers:

2

Working with a Java console application, I can do this:

java -agentlib:hprof=heap=dump,format=b MyClass

Then I can hit ctrl-\ (or ctrl-break on Windows) any time I would like to take a snapshot of the heap for later analysis.

I would like to do the same thing for a Java Web Start application, but I cannot seem to get that to work. I can pass in the agentlib argument with the JAVAWS_VM_ARGS environment variable, but entering ctrl-\ and ctrl-break in the console doesn't seem to do anything. All I get is one dump, when the program starts, which isn't really interesting since at that point I haven't even logged into our program yet and executed the transactions I want to analyze.

A: 

You could use VisualVM to take heap dumps from the running application. VisualVM lets you browse and save the heap dumps.

Mark
Cool ... this is included in Java 1.6.0_7 and later...
skiphoppy
Unfortunately, it seems our Java Web Start application crashes when I try to profile its memory with VisualVM.
skiphoppy
+1  A: 

Start your application with the following JMV arguments to enable JMX and boot a listener on port 9004:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port="9004"
-Dcom.sun.management.jmxremote.authenticate="false"
-Dcom.sun.management.jmxremote.ssl="false"

Then have a look at this Java program which can make a connection to the JMX server and take a heap dump on demand. The source code includes comments with links to 2 useful articles on the internet that helped me get all of this working. Good luck !

Link: JmxHeapDumper.java

P.S. apparently getting JMX to start for a WebStart app is tricky, I found this discussion, hope it helps: http://forums.java.net/jive/message.jspa?messageID=311717

Peter Thomas