user242591
user242591

Reputation: 489

JVM thread dump location

When I issue a kill -3 <pid> command to my Java program, it generates the thread dump on the console. How do I redirect this to a file?

Upvotes: 15

Views: 28403

Answers (4)

Arnab Biswas
Arnab Biswas

Reputation: 4605

Please append following JVM arguments to your application. Thread dump should be captured at dump.log.

-XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=dump.log

Please note it does not redirect, but enables JVM diagnostic logging. So, there could be possible over head as well.

However, if you can have JDK in the environment, using jstack or jcmd (jcmd is preferred with JDK 1.8), you can capture thread dump and redirect to a file.

Upvotes: 0

Shane
Shane

Reputation: 1285

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

Upvotes: 2

trashgod
trashgod

Reputation: 205885

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

Upvotes: 3

ZoogieZork
ZoogieZork

Reputation: 11289

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

Upvotes: 23

Related Questions