kill -3 to get java thread dump

2019-01-05 08:49发布

I am using kill -3 command to see the JVM's thread dump in unix. But where can I find the output of this kill command? I am lost!!

9条回答
小情绪 Triste *
2楼-- · 2019-01-05 09:20
  1. Find the process id [PS ID]
  2. Execute jcmd [PS ID] Thread.print
查看更多
再贱就再见
3楼-- · 2019-01-05 09:23

With Java 8 in picture, jcmd is the preferred approach.

jcmd <PID> Thread.print

Following is the snippet from Oracle documentation :

The release of JDK 8 introduced Java Mission Control, Java Flight Recorder, and jcmd utility for diagnosing problems with JVM and Java applications. It is suggested to use the latest utility, jcmd instead of the previous jstack utility for enhanced diagnostics and reduced performance overhead.

However, shipping this with the application may be licensing implications which I am not sure.

查看更多
在下西门庆
4楼-- · 2019-01-05 09:26

There is a way to redirect JVM thread dump output on break signal to separate file with LogVMOutput diagnostic option:

-XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=jvm.log
查看更多
啃猪蹄的小仙女
5楼-- · 2019-01-05 09:26

In the same location where the JVM's stdout is placed. If you have a Tomcat server, this will be the catalina_(date).out file.

查看更多
霸刀☆藐视天下
6楼-- · 2019-01-05 09:26

When using kill -3 one should see the thread dump in the standard output. Most of the application servers write the standard output to a separate file. You should find it there when using kill -3. There are multiple ways of getting thread dumps:

  • Kill -3 : Gives output to standard output.
  • If one has access to the console window where server is running, one can use Ctrl+Break combination of keys to generate the stack trace on std output.
  • For hotspot VM we can also use jstack command to generate thread dump. It’s a part of the JDK. Syntax is as follows: Usage: jstack [-l] (to connect to running process) jstack -F [-m] [-l] (to connect to a hung process)
  • For JRockit JVM we can use JRCMD command which comes with JDK Syntax: jrcmd [ []] [-l] [-f file] [-p] -h]
查看更多
仙女界的扛把子
7楼-- · 2019-01-05 09:27

In Jboss you can perform the following

nohup $JBOSS_HOME/bin/run.sh -c  yourinstancename $JBOSS_OPTS >> console-$(date +%Y%m%d).out  2>&1 < /dev/null &
kill -3 <java_pid>

This will redirect your output/threadump to the file console specified in the above command.

查看更多
登录 后发表回答