你能试试看下面是否适合你。
TARGET_THREAD_ID=xxx JAVA_PID=$(ps -ef | grep "[org].apache.catalina.startup.Bootstrap" | awk '{print $2}'); jstack -F ${JAVA_PID} | sed -n -e "/Thread ${TARGET_THREAD_ID}/,/Thread /p" | head -n -1
这将打印如下内容
Thread xxx: (state = BLOCKED)
- java.lang.Object.wait(long) @bci=0 (Compiled frame; information may be imprecise)
- java.lang.Object.wait() @bci=2, line=502 (Compiled frame)
- java.lang.ref.Reference.tryHandlePending(boolean) @bci=54, line=191 (Compiled frame)
- java.lang.ref.Reference$ReferenceHandler.run() @bci=1, line=153 (Compiled frame)