如何编写可分析的线程转储格式
我正在创建一个全局异常处理,它在某些情况下关闭之前收集一些信息。这些信息之一是当前线程转储。我使用以下代码执行此操作:
ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
问题是将信息写入 TDA 可分析的格式。有没有一种“简单”的方法来格式化信息,而不是自己编写格式?
编辑:我想要一个完整的线程转储,这样我就可以找到有问题的线程。上面提到的方法提供了一个 ThreadInfo-Objects 数组,所以我有数据。我的问题是写入的输出不是 TDA 识别为线程转储的格式。
I'm creating a global exception handling which collects some information before shutting down in some cases. One of this information is the current thread dump. i do this with following code:
ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
The problem is to write the information into a analyzable format for TDA. Is there a "simple" way to format the information instead of writing the format on my own?
EDIT: I'd like to have a full thread dump so I can find problematic threads. The above mentioned method delivers an array of ThreadInfo-Objects, so i have the data. My problem is that the written output isn't in a format TDA recognizes as thread dump.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用的是 Windows,则 bwithers 有 描述了一种向 JVM 发送线程转储信号的方法。
还有一个纯java方法,但我不是确保输出采用标准格式。
If you're on windows, then bwithers has described a way to signal the JVM to thread dump.
There's also a pure java approach, but I'm not sure that the output is in standard format.
只需使用 TDA 使用自身转储 JMX 数据的代码: MBeanDumper.java
Just use the code TDA uses itself to dump JMX-data: MBeanDumper.java
如果您不想复制 TDA 代码(毕竟是 LGPL),您也可以使用 Attach API 来获取标准格式的数据。据我所知,执行转储的唯一 JVM 内置代码是 Attach 代理中的本机代码。
数据转储将以字符数据流的形式返回转储。
If you don't want to copy the TDA code (It is LGPL, after all) you can also use the Attach API to get data in the standard format. As far as I know, the only JVM built-in code to do the dump is native code in the Attach agent.
The data dump will return the dump in a stream of character data.