How do I create a thread dump via JMX?

时光总嘲笑我的痴心妄想 提交于 2019-11-29 07:03:16

You can use the ThreadMXBean management interface.

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

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

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

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.

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.

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_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:

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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!