JDK内置工具-jstack-查看进程的状态以及异常诊断

SYNOPSIS-使用方法

jstack [ option ] pid
jstack [ option ] executable core
jstack [ option ] [server-id@]remote-hostname-or-IP

 

PARAMETERS-参数说明

Options are mutually exclusive. Option, if used, should follow immediately after the command name. See OPTIONS.

  • pid

  • process id for which the stack trace is to be printed. The process must be a Java process. To get a list of Java processes running on a machine, jps may be used

  • executable

  • Java executable from which the core dump was produced.

  • core

  • core file for which the stack trace is to be printed.

  • remote-hostname-or-IP

  • remote debug server's (see jsadebugd) hostname or IP address.

  • server-id

  • optional unique id, if multiple debug servers are running on the same remote host.

DESCRIPTION

jstack prints Java stack traces of Java threads for a given Java process or core file or a remote debug server. For each Java frame, the full class name, method name, 'bci' (byte code index) and line number, if available, are printed. With the -m option, jstack prints both Java and native frames of all threads along with the 'pc' (program counter). For each native frame, the closest native symbol to 'pc', if available, is printed. C++ mangled names are not demangled. To demangle C++ names, the output of this command may be piped to c++filt. If the given process is running on a 64-bit VM, you may need to specify the -J-d64 option, e.g.:

jstack -J-d64 -m pid #对于在64位的jvm 要加上 -d64

 

NOTE - This utility is unsupported and may or may not be available in future versions of the JDK. In Windows Systems where dbgeng.dll is not present, 'Debugging Tools For Windows' needs to be installed to have these tools working. Also, PATH environment variable should contain the location of jvm.dll used by the target process or the location from which the Crash Dump file was produced.

For example, set PATH=<jdk>\jre\bin\client;%PATH%

OPTIONS-可以输入参数

  • -F

  • Force a stack dump when 'jstack [-l] pid' does not respond.

  • -l 可以查看线程是否被锁

  • Long listing. Prints additional information about locks such as list of owned java.util.concurrent ownable synchronizers.

  • -m

  • prints mixed mode (both Java and native C/C++ frames) stack trace.

  • -h

  • prints a help message.

  • -help

  • prints a help message

SEE ALSO 参考博文:https://dzone.com/articles/how-to-take-thread-dumps-7-options

. jstack

‘jstack’ is an effective command line tool to capture thread dumps. The jstack tool is shipped in JDK_HOME\bin folder. Here is the command that you need to issue to capture thread dump:

jstack -l  <pid> > <file-path>

Where:

pid: is the Process Id of the application, whose thread dump should be captured

file-path: is the file path where thread dump will be written in to.

Example:

jstack -l 37320 > /opt/tmp/threadDump.txt

As per the example thread dump of the process would be generated in /opt/tmp/threadDump.txt file.

Jstack tool is included in JDK since Java 5. If you are running in older version of java, consider using other options

另 jstack 要用和java进程同一个unix账号下使用

另外可以参考博文:

http://www.blogjava.net/jzone/articles/303979.html

另外关于每个线程的状态所表示的意义可以参考博文:

http://www.cnblogs.com/zhengyun_ustc/archive/2013/03/18/tda.html

http://gudaoqing.blog.51cto.com/7729345/1332829

转载于:https://my.oschina.net/u/2308739/blog/608466

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值