java - jstack - 不包含线程堆栈跟踪
问题描述
在使用 jstack 了解特定进程的线程时。对于众多线程,我找不到任何堆栈跟踪。
"Thread-4978" #5139 prio=5 os_prio=0 tid=0x000000001d451800 nid=0x8530 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Thread-4808" #4969 prio=5 os_prio=0 tid=0x000000001d44f000 nid=0x8eb0 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
除了可运行状态之外,我无法从中获取任何信息。请指导我调试问题。
解决方案
Java thread has no Java stack trace, when
- The thread is about to start, and is running pre-start initialization or JVM TI
ThreadStart
handler. - The thread is about to terminate, and is running post-exit cleanup or JVM TI
ThreadEnd
handler. - The thread is a JVM TI agent thread, which is running native code.
To find out what these threads are doing, it's not enough to get Java stack trace - you'd need to get native stack traces as well.
On JDK 8 run
jstack -m <pid>
On JDK 11 and later
jhsdb jstack --mixed --pid <pid>
Another option is to use a profiler which is aware of native stacks, e.g. async-profiler
When used in threaded mode (-t
), async-profiler can show mixed stack traces of all threads in the JVM, even if they have no Java stack trace.
For example, when I debugged a similar issue, async-profiler showed me the following stack trace:
In my case, this was a JDWP agent running post-thread-end hook. Note that the standard Java debug agent (libjdwp) is a particular case of a JVM TI agent, which has non-trivial ThreadEnd
handler.
This was a bug JDK-8227269 that resulted in slow termination of threads. So, if you experience problems with debug agent turned on, the first recommendation is to run JVM without JDWP.
推荐阅读
- c# - ActionFilter 不适用于 AJAX 调用
- php - 如果用户在刀片文件中经过身份验证,我如何签入 Laravel?
- spring - Spring Cloud Config Server 独立存储库
- javascript - 根据背景颜色滚动时更改 SVG 填充
- ios - 在 Swift 中向 SKStoreReviewController 添加功能
- node.js - 我们的 Heroku 服务器端口 443 被阻塞
- typescript - AWS cdk deploy --all 创建 ECS 服务失败
- android - Android - 防止用户在键盘之间切换
- javascript - 深拷贝 Object 添加一个 key : value
- sql - 没有间隙的 SQL 自动增量——解决方法/最佳实践