您可以挂起 Java 应用程序并从应用程序内获取其线程的快照吗?
我正在考虑编写在 Java 应用程序内部运行的监视代码,并定期拍摄正在运行的线程的快照并显示每个线程的一些调用堆栈信息。
理想情况下,这将扩展到分析和/或监控。
我不想使用外部工具,因为这是出于自学目的。
I'm looking at writing monitoring code that runs inside a Java application and periodically takes a snapshot of running threads and displays some call stack information on each.
Ideally this would be extended for profiling and/or monitoring.
I don't want to use an external tool, as this is for self educational purposes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您是否尝试过 Thread.getAllStackTraces()
Have you tried Thread.getAllStackTraces()
看一下 ThreadMXBean.dumpAllThreads(boolean, boolean)
Take a look at
ThreadMXBean.dumpAllThreads(boolean, boolean)
您是否研究过 Thread< 的方法/a> 类,例如 Thread.enumerate()、Thread.activeCount()、Thread.getName() ?
Have you looked into the methods of the Thread class such as
Thread.enumerate()
,Thread.activeCount()
,Thread.getName()
?您可以在创建时注册想要监视的线程,并使用单独的指标线程来进行监视。您可能希望在线程中构建某些指标,例如最近运行时间的列表、当前吞吐量或其他类型的指标。
You could register the threads you want to watch at creation time, and have a separate metrics thread to do the monitoring. You would want to build certain metrics into the thread, such as maybe a list of recent running times, current throughput, or other sorts of metrics.
Kill -SIGQUIT {java_process}
将转储 java 进程的 stdout 中的所有堆栈跟踪。
kill -SIGQUIT {java_process}
will dump all stack traces in the stdout of the java process.