jstack used 使用jstack
实用程序的故障(troubleshooting)排除技的用途/场景:
Troubleshoot with jstack Utility
Force a Stack Dump (jstack -F <pid>
,macos 用jhsdb jstack
替代)
Stack Trace from a Core Dump (jstack $JAVA_HOME/bin/java core
,macos 用
jhsdb jstack` 替代)
Mixed Stack (jstack -m <pid>
,macos 用jhsdb jstack
替代)
jstack trace thread stats jstack
排查thread
是一个常用场景,以此为例:
1 2 3 4 #jps/jcmd 查找java进程 # 排查出blocking thread id $ top -Hp <<pid>>
1 2 3 # 将thread id 转换为16进制 # 6821 printf "%x\n" 26657
使用jstack
排查该thread
:
1 $ jstack 47377 | grep -20 6821
当thread
处于BLOCKED
/WAITING
需要重点观察。
jstack Mixed Stack 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 jstack -m 10537 Attaching to process ID 10537, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.181-b13 Deadlock Detection: No deadlocks found. ----------------- 10538 ----------------- 0x00007ff192812a35 __pthread_cond_wait + 0xc5 0x00007ff191938f15 _ZN13ObjectMonitor4waitElbP6Thread + 0xa75 0x00007ff191748272 JVM_MonitorWait + 0x182 0x00007ff17d0186c7 * java.lang.Object.wait(long) bci:0 (Interpreted frame) 0x00007ff17d0082bd * java.lang.Object.wait() bci:2 line:502 (Interpreted frame) 0x00007ff17d0082bd * org.eclipse.jetty.util.thread.QueuedThreadPool.join() bci:18 line:391 (Interpreted frame) 0x00007ff17d008302 * org.eclipse.jetty.server.Server.join() bci:4 line:411 (Interpreted frame) 0x00007ff17d0082bd * com.hortonworks.support.tools.server.SupportToolServer.run() bci:1287 line:304 (Interpreted frame) 0x00007ff17d0082bd * com.hortonworks.support.tools.server.SupportToolServer.main(java.lang.String[]) bci:48 line:651 (Interpreted frame) 0x00007ff17d0007a7 <StubRoutines> 0x00007ff1916b5a76 _ZN9JavaCalls11call_helperEP9JavaValueP12methodHandleP17JavaCallArgumentsP6Thread + 0x1056 0x00007ff1916f71c2 _ZL17jni_invoke_staticP7JNIEnv_P9JavaValueP8_jobject11JNICallTypeP10_jmethodIDP18JNI_ArgumentPusherP6Thread + 0x362 0x00007ff191713a2a jni_CallStaticVoidMethod + 0x17a 0x00007ff1925f90ff JavaMain + 0x81f
扩展 Oracle在JDK文档建议使用jcmd
替代jstack
.
参考