简体   繁体   English

使用jstack进行线程转储

[英]Taking thread dump using jstack

I would like to generate an automatic thread dump. 我想生成一个自动线程转储。 This is the script I am using. 这是我正在使用的脚本。

    THREADDUMP_LOG_FILE="/tmp/tmpLog_`date +"%Y%m%d%H%M%S"`"
    pid=`ps axww | grep -v grep | sed -e 's/^[ ]*//g' | sed -e 's/[ ][ ]*/ /g' | cut -f1 -d' ' `
    $JAVA_HOME/bin/jstack $pid >> $THREADDUMP_LOG_FILE

When I do this, this is what I see in the thread dump log file. 当我这样做时,这就是我在线程转储日志文件中看到的内容。

Usage:
jstack [-l] <pid>
    (to connect to running process)
jstack -F [-m] [-l] <pid>
    (to connect to a hung process)
jstack [-m] [-l] <executable> <core>
    (to connect to a core file)
jstack [-m] [-l] [server_id@]<remote server IP or hostname>
    (to connect to a remote debug server)

Options:
    -F  to force a thread dump. Use when jstack <pid> does not respond (process is hung)
    -m  to print both java and native frames (mixed mode)
    -l  long listing. Prints additional information about locks
    -h or -help to print this help message

Clearly, I am doing something wrong. 显然,我做错了。 Can someone please guide me here on how to take a thread dump using jstack? 有人可以在这里指导我如何使用jstack进行线程转储吗?

I have no direct answer, but I assume that the shell-foo-magic you do to get the PID is perhaps wrong. 我没有直接的答案,但是我认为您为获取PID所做的shell-foo-magic可能是错误的。 Therefore could you please add an 'echo $PID' directly after the pid=... line and showus the output. 因此,您能否在pid = ...行之后直接添加“ echo $ PID”并显示输出。 Because useing directly 'jstack ' works fine for me. 因为直接使用'jstack'对我来说很好。

You can't give more than one pid to jstack, and you should give it a pid of java process only. 您不能给jstack多个pid,而应该给它一个java进程的pid。 Something like this should work: 这样的事情应该起作用:

for pid in $(ps axww | grep ' java' |grep -v grep | sed -e 's/^[ ]*//g' | sed -e 's/[ ][ ]*/ /g' | cut -f1 -d' '); do
  jstack $pid >> $THREADDUMP_LOG_FILE
done

Or more simply: 或更简单地说:

for pid in $(jps | sed 's/^\([0-9][0-9]*\) .*$/\1/'); do
  jstack $pid >> $THREADDUMP_LOG_FILE
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 java 上使用 jstack 进行线程转储失败并出现套接字文件错误 - Taking thread dump with jstack on java fails with socket file error jstack线程转储是否一致? - Is jstack thread dump consistent? 没有jstack的Java线程转储 - Java thread dump without jstack 从冻结的Java应用程序获取线程转储而不使用JStack - Getting a thread dump from a frozen Java app without using JStack 如何在EC2 Amazon中获取Java线程转储:找不到jstack - How to get Java thread dump in EC2 Amazon : No jstack found Java应用程序死锁,但在使用jstack转储线程后已解锁 - java app deadlock but unlocked after use jstack to dump thread 使用 jstack 清空 Tomcat 线程转储 - Empty Tomcat thread dumps using jstack jstack无法创建线程转储-线程745 :(状态=已阻止)在堆栈移动期间发生错误) - jstack Can't create thread dump - Thread 745: (state = BLOCKED) Error occurred during stack walking) 为什么 jstack 在尝试生成线程转储时无法打开套接字文件? - Why is jstack unable to open socket file when trying to generate a thread dump? Java 进程在我使用 jstack -F 进行线程转储后不会重新启动而是恢复 - Java process not respoding but resuming after I do a thread dump with jstack -F
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM