tags:

views:

406

answers:

4

Hi,

when I issue a kill -3 command to my java program, its generates the thread dump on the console. How do I redirect this to a file?

Tks!

A: 

Hi,

You could use: kill -3 Process ID > dump.txt

Cheers, Shane

Shane
no. this is not right imo. you're redirecting the output of the kill command here. we should be redirecting the output of the jvm.
I'm not sure about other platforms, but on Linux at least this doesn't work since the thread dump is written to the standard out of the *Java* process, not the current console, so `dump.txt` will be empty.
ZoogieZork
That answer was unconfirmed as I was at work on Windows machine. Sorry for the bad information.
Shane
+3  A: 

Two options:

Run your Java application with stdout redirected

java com.example.MyApp > out.txt

Use jstack instead.

The jstack utility allows you to get a thread dump and send the output to the current console instead of the stdout of the Java application, allowing you to redirect it.

For example, if the PID of your Java application is 12345 (use the jps utility to find it quickly):

jstack 12345 > threads.txt
ZoogieZork
+1  A: 

If you want details of all threads and other JVM details, try jconsole.

Cheers, Shane

Shane
+1  A: 

I usually use the NetBeans profiler, but jvisualvm is available from the command line.

trashgod