tags:

views:

5429

answers:

8

I have a Java application that I run from a console which in turn exec's another Java process. I want to get a thread/heap dump of that child process. On Unix I could do a "kill -3 " but on Windows AFAIK the only way to get a thread dump is Ctrl-Break in the console. But that only gives me the dump of the parent process, not the child. Is there another way to get that heap dump?

+1  A: 

You can send the kill -3 from cygwin. You have to use the cygwin ps options to find windows processes then just send the signal to that process.

krosenvold
+1  A: 

You have to redirect output from second java executable to some file. Then, use SendSignal to send "-3" to your second process.

Yoni Roit
+1  A: 

See www.adaptj.com for a commercial utility that will allow you to generate stack dumps on Windows. It seems to be free in many situations.

Darron
+2  A: 

You could run jconsole (included with Java 6's SDK) then connect to your Java application. It will show you every Thread running and its stack trace.

Steve Kuo
+1  A: 

I recommend the Java VisualVM distributed with the JDK (jvisualvm.exe). It can connect dynamically and access the threads and heap. I have found in invaluable for some problems.

Software Monkey
+1  A: 

In addition to using the mentioned jconsole/visualvm, you can use jstack -l <vm-id> on another command line window, and capture that output.

The can be found using the task manager (it is the process id on windows and unix), or using jps.

Both jstack and jps are include in the Sun JDK version 6 and higher.

ankon
+2  A: 

You can use jmap to get a dump of any process running, assuming you know the pid. Use Task Manager or Resource Monitor to get the pid. Then jmap -dump:format=b,file=cheap.bin to get the heap for that process.

rkaganda