java 如何通过 JMX 创建线程转储?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3958938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 04:09:29  来源:igfitidea点击:

How do I create a thread dump via JMX?

javajconsolejstack

提问by ripper234

I have a Tomcat running as a Windows Service, and those are known not to work well with jstack. jconsole is working well, on the other hand, and I can see stacks of individual threads (I'm connecting to "localhost:port" to access it).

我有一个作为 Windows 服务运行的 Tomcat,众所周知,它们与 jstack 不能很好地配合使用。另一方面,jconsole 运行良好,我可以看到单个线程的堆栈(我正在连接到“localhost:port”以访问它)。

How can I use jconsole or a similar tool to dump all the thread stacks into a file? (similar to jstack)

如何使用 jconsole 或类似工具将所有线程堆栈转储到文件中?(类似于jstack)

回答by dogbane

You can use the ThreadMXBeanmanagement interface.

您可以使用ThreadMXBean管理接口。

This FullThreadDumpclass demonstrates the capability to get a full thread dump and also detect deadlock remotely using JMX.

这个FullThreadDump类演示了获取完整线程转储以及使用 JMX 远程检测死锁的能力。

回答by Claudio

Nowadays you can use jvisualvm tool to connect to your remote JVM through JMX and create a thread dump. Don't know if this was available

现在,您可以使用 jvisualvm 工具通过 JMX 连接到远程 JVM 并创建线程转储。不知道这个有没有

Java VisualVM

Java可视化虚拟机

回答by Gray

Here's another code sample that will write a stack dump to a file:

这是将堆栈转储写入文件的另一个代码示例:

http://pastebin.com/zwcKC0hz

http://pastebin.com/zwcKC0hz

We use this over JMX to give us an approximation of the stack dump you get when you make a JMX request or if the process detects high, unexpected load.

我们在 JMX 上使用它来为我们提供当您发出 JMX 请求或进程检测到高、意外负载时获得的堆栈转储的近似值。

回答by Sanjeet Pandey

It would be helpful if you take a flight recording to get a deeper view on the JVM behavior, specially focusing on the Hot Methods.

如果您进行飞行记录以更深入地了解 JVM 行为,特别是关注热方法,这将很有帮助。

Usually, a recording of half an hour is enough. To trigger a recording, you must be logged in to the machines, and issue the following command:

通常,录制半小时就足够了。要触发录制,您必须登录到机器,并发出以下命令:

If using Java HotSpot 1.8.x:

如果使用 Java HotSpot 1.8.x:

$JAVA_HOME/bin/jcmd VM.unlock_commercial_features $JAVA_HOME/bin/jcmd JFR.start duration=1800s settings=profile filename=/tmp/recording.jfr

$JAVA_HOME/bin/jcmd VM.unlock_commercial_features $JAVA_HOME/bin/jcmd JFR.start duration=1800s settings=profile filename=/tmp/recording.jfr

IF using java HotSpot 1.7.x:

如果使用 java HotSpot 1.7.x:

Edit your $HOME/conf/wrapper.conf file by adding the following parameters on JVM startup:

通过在 JVM 启动时添加以下参数来编辑您的 $HOME/conf/wrapper.conf 文件:

wrapper.java.additiona.=-XX:+UnlockCommercialFeatures wrapper.java.additional.=-XX:+FlightRecorder

wrapper.java.additiona.=-XX:+UnlockCommercialFeatures wrapper.java.additional.=-XX:+FlightRecorder

(replace with the corresponding positional number )

(替换为对应的位置编号)

Then, have your instances restarted. Once done, issue the following command :

然后,重新启动您的实例。完成后,发出以下命令:

$JAVA_HOME/bin/jcmd JFR.start duration=1800s settings=profile filename=/tmp/recording.jfr

$JAVA_HOME/bin/jcmd JFR.start duration=1800s settings=profile filename=/tmp/recording.jfr

The flight recording wil produce a file on /tmp/recording.jfr upon termination.

飞行记录将在终止时在 /tmp/recording.jfr 上生成一个文件。