Quick access to memory and thread information in Java (MBean)

Source: Internet
Author: User

When troubleshooting online issues, we often use Jstat, Jstack, jmap to view GC, memory, and thread information, but sometimes we need to get a whole lot of information to help us quickly locate, like the top command in Linux, simple and comprehensive system information, Find some information on the Internet, found that someone had written a jtop tool, to get a full picture of Java application Information, a look at the author, the original is Ali's colleagues, the principle is to use the Mbean in Java, take this opportunity to the mbean things a simple understanding.

How to use this tool first: wget Https://hatter-source-code.googlecode.com/svn/trunk/jtop/jtop.jar

Usage:

JAVA&NBSP;-JAR&NBSP;JTOP.JAR&NBSP;[OPTIONS]&LT;PID&GT;[&LT;INTERVAL&GT;[&LT;COUNT&GT]]-or-java -cp  JTOP.JAR&NBSP;JTOP&NBSP;[OPTIONS]&LT;PID&GT;[&LT;INTERVAL&GT;[&LT;COUNT&GT]]     -size  <b| k| m| G| H>             size,case insensitive   (Default: b, h for human)     -thread <N>                     threadtop n  (Default:5)     -stack <N>                     stacktracetop n   (Default:8)     -excludes                      excludes (string.contains)    & Nbsp;-includes                      includes (string.contains, excludes than includes)      --color                        Display color  (Default: off)      --sortmem                      Sortby memory allocted  (Default: off)      --summaryoff                    Donot display summary  (Default: off)

(1) Directly run Jtop.jar get the information (sudo-u Admin/java-jar jtop.jar pid memory, Thread, GC, high CPU consuming thread stack information)

If you want to convert the size of the information into m or other, you can use another way

Sudo-u admin java-cp Jtop.jar jtop-size M PID

(2) View the top three thread stack information for CPU (sudo-u admin java-cp jtop.jar jtop-thread 3-stack PID)

(1) Some concepts

A, MBean

Typically a Java class that provides an interface that enables the class to have administrative functions (such as the standard Mbean, the methods defined in the interface that make the MBean manageable).

B, MBean Server

Is a Java class that manages Mbean, you need to register an Mbean with Mbean server, this mbean will have administrative function, Mbean server also provides the function of querying and registering listeners, Sun provides only interface, The Mbean server implementations in different JMX implementations are also different.

There are four common types of MBean: A, standard mbean;b, dynamic mbean;c, open mbean;d, model Mbean

Highlights a standard Mbean and dynamic Mbean

Standard Mbean: This type of Mbean is the simplest, the resources it can manage (including attributes, methods, time) must be defined in the interface, and then the Mbean must implement this interface. Its name must also follow certain specifications, for example, if our Mbean is Hello, then the interface must be Hellombean.

Dynamic MBean: The Javax.management.DynamicMBean interface must be implemented, all properties, methods are defined at run time

(2) Access to information based on the Mbean provided by JDK

1, the factory class to obtain each Mbean:managementfactory

2, Memory information Mbean:memorymxbean

3, thread information Mbean:threadmxbean, you can focus on dumpallthreads, all the thread information down, and then do their own operations

4. GC Information Mbean:garbagecollectormxbean

Managementfactory.getgarbagecollectormxbeans () gets an array of Gcmbean

5. Class Loading Mbean:classloadingmxbean

Http://docs.huihoo.com/java/jmx/jmx.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.