Use jdk's own running monitoring tool JConsole to observe and analyze the running of Java programs

 Original address: http://blog.csdn.net/libaolin198706231987/article/details/55057149

 

1. What is JConsole

    JConsole has been introduced since Java 5. JConsole is a built-in Java performance analyzer that can be run from the command line or in a GUI shell. You can easily use JConsole (or, its higher-end "closer" VisualVM ) to monitor Java application performance and trace code in Java.

2. How to start JConsole

  1. If you are starting from the command line, make the JDK on the PATH and run jconsole.
  2. If starting from a GUI shell, find the JDK installation path, open the bin folder, and double-click  jconsole  .

    When the profiling tool pops up (depending on the version of Java running and the number of Java programs running), a dialog may appear asking for the URL of a process to connect to, or it may list many different local Java processes (sometimes contains the JConsole process itself) to connect. as the picture shows:

To analyze that program, double-click the process.

3. How to set JAVA program runtime to be analyzed by JConsolse connection

  1. Local programs (relative to the computer where JConsole is turned on), can be connected to JConsole that can be opened locally without setting any parameters (Java SE 6 does not need to set up, before it still needs to set the runtime parameter - Dcom.sun.management.jmxremote )
  2. Unauthenticated connection (the following settings indicate that the connection port is 8999 and can be connected without authentication)
    1. -Dcom.sun.management.jmxremote.port=8999 \  
    2. -Dcom.sun.management.jmxremote.authenticate=false \  
    3. -Dcom.sun.management.jmxremote.ssl=false  
     
  3. If security factors are considered, authentication is required, and a secure connection is required, it can be done. Reference: http://download.oracle.com/javase/6/docs/technotes/guides/management/agent.html#gdenv

Fourth, how JConsole connects to the JAVA program of the remote machine (for example)

1. Write a simple JAVA program that runs all the time, running on a certain machine such as (192.168.0.181)

  1. java -cp . -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.managent.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false JConsoleTest  

 

2. Connect to another machine

You can use the command directly:

  1. jconsole.exe 192.168.0.181:8999  

 You can also operate the connection in the already opened JConsole interface -> create a new connection -> select a remote process -> enter the remote host IP and port number -> click "connect", as shown in the figure:


 

 Then you will enter the analysis interface: 

performance analysis

Let's talk about how to analyze and how to use these six labels

  • 概述: Displays overview information about the Java VM and monitored values.
  • Memory:  Displays memory usage information
  • Thread:  Display thread usage information
  • class:  show class loading information
  • *VM Summary: *Display java VM information
  • MBeans:  Displays MBeans.

Overview


 

    概述很简单没啥说的,自己看看吧,不过值得一提的是对着图点击右键可以保存数据到CSV文件,以后可以使用其他工具来分析这些数据。

内存


    这个比较有价值,参看堆内存,非堆内存,内存池的状况总体内存的分配和使用情况以及不同的GC进行垃圾回收的次数和时间。可以手动进行GC查看内存变化。

 

   在分析JAVA内存问题进行调优时候非常有用,你要学习JVM内存模型,之后会发现这里的每个值都具有意义。

 

   GC的算法和参数对性能有显著的影响,注意垃圾回收次数、时间、以及partial GC和full GC,调整你所使用的不同GC和以及各个GC下的参数,然后在这个视图下观察,以得到好的性能。

 

这里贴一下 Java HotSpot VM garbage collector 下generational GC 的各代的划分图:


 

关于GC,可以参考:http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html

线程

   左下角显示所有的活动线程(如果线程过多,可以在下面的过滤栏中输入字符串过滤出你想要观察的线程)。点击某个显示会显示这个线程的名称、状态、阻塞和等待的次数、堆栈的信息。

 

    统计图显示的是线程数目的峰值(红色)和当前活动的线程(蓝色)。

 

   另外下面有个按钮“检测到死锁”,有时候会有用处。


 没啥要说的。

VM摘要


 也没啥要说的,看看吧,内存状况,操作系统...

MBean


 

这里可以有一些额外的操作。

插件

  1. jconsole -pluginpath C:\Java\jdk1.6.0_22\demo\management\JTop\JTop.jar  


 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326078684&siteId=291194637