Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the visual monitoring tool of java

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Java visual monitoring tools how to use, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

In a word: jdk's own monitoring tools jconsole and jvisualvm can be more convenient and intuitive to monitor the performance of java applications. Here is how to use them.

1 introduction

Previous articles (see "related reading" below) have introduced jdk command-line tools, but they are not intuitive enough to use, and generally need to be used on the local machine, is there a more convenient and intuitive way to monitor java applications? In fact, jdk itself already provides GUI tools for java monitoring, which are jconsole and jvisualvm. The function and use of these two tools are described below.

2 jconsole usage

Jconsole is a built-in Java performance analyzer for jdk. In the bin directory under the JDK installation directory, under windows, you can start running from the command line (jconsole.exe) or directly double-click jconsole.exe. Readers who are interested can refer to the official documentation for the use of jconsole tools: https://docs.oracle.com/javase/8/docs/technotes/guides/management/jconsole.html

2.1 two connection modes

When jconsole starts, it provides two connection methods, namely, connecting to local processes and connecting to remote processes. It will directly list the local java process to select. If you need to monitor a remote java process, check the remote process and enter:. This requires setting the remote connection parameters of JMX when the remote java process starts, otherwise it cannot be connected. For the JMX technology of remote connection, you can refer to the official article (https://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html) as follows:

# the server IP-Djava.rmi.server.hostname=192.168.222.10# that needs to be monitored provides the java process port for monitoring-Dcom.sun.management.jmxremote.port=9004 # specifies the subsequent communication port, which is the same as above-Dcom.sun.management.jmxremote.rmi.port=9004 # does not log in using ssl. If there is a security requirement, you can set-Dcom.sun.management.jmxremote.ssl=false # No verification. If there is a security requirement, you can set-Dcom.sun.management.jmxremote.authenticate=false.

As shown in the following figure:

Note that since you do not use ssl, you will be prompted with "insecure connection". Just click on it.

2.2 use of jconsole function

After starting and connecting the java process, the interface of jconsole is relatively simple, which is divided into six modules:

Overview: an overview of the java process, including a line chart of changes in heap, number of threads, classes, and CPU occupancy.

Memory: displays heap and non-heap memory usage information, similar to jmap and jstat

Threads: displays thread usage information, similar to jstack

Classes: displaying class loading information

VM summary: displays JVM information, similar to jinfo

MBeans: displays MBeans information (less used)

2.2.1 Overview

The overview mainly shows the changes in heap, number of threads, classes, and CPU occupancy. Basically, you can view the application profile directly according to the line chart. If the heap occupies a lot of memory, has a large number of active threads, and has a high CPU occupancy rate, you can go directly to the corresponding area and look at the details to find out why. In addition, right-click the corresponding figure, you can export the data to the csv file for analysis. As shown in the figure:

2.2.2 memory

Memory is the key area we monitor. You can see heap memory, non-heap memory, memory pool status, GC times and time, and you can manually GC to see memory changes. As shown below:

At the top of the figure, you can choose which memory changes to view (heap, non-heap, old area, eden area, survivor area, metaspace area, etc.), or you can manually execute GC to check the changes. At the bottom of the figure shows the size and usage of memory, the number of times and usage time of GC, and shows the changes of heap and non-heap in a bar chart. Therefore, for problems such as memory overflow and OOM, the monitoring data here is very suitable.

2.2.3 Thread

For online applications, the main reasons for long thread pauses are: waiting for external resources (database connection, network resources, device resources, etc.), dead loop, lock waiting (live lock and deadlock), which need to monitor the thread running status of java application, as shown below:

Analyze the changes in the number of threads and click on a thread to view the running status, in which you can also click the "detect deadlock" function to deal with the deadlock problem.

2.2.4 classes

This feature is mainly used to see the total number of loaded classes, and if the loaded classes are increasing all the time, you have to check to see if the code continues to generate classes. As shown below:

2.2.5 VM Summary

When we add startup parameters (JAVA_OPTS) to the java application, if you want to check the actual use of the application online and whether the parameters are valid, we use jinfo as the command line tool, which can now be seen directly here, and includes system information, class information, heap information and related VM parameters. As shown below:

3 jvisualvm usage

Similar to jconsole, jdk also provides jvisualvm tools in the bin directory, and jvisualvm is relatively more powerful. Under windows, you can start running from the command line (jvisualvm.exe) or directly double-click jvisualvm.exe. Readers who are interested can refer to the official documentation for the use of jvisualvm tools: https://docs.oracle.com/javase/8/docs/technotes/guides/visualvm/index.html

3.1 two connection modes

Like jconsole, jvisualvm can monitor both local java processes and remote java processes. The local process can be selected directly, and the remote process also needs to add JMX startup parameters to the java process.

3.2 use of jvisualvm function

Jvisualvm is quite powerful and mainly includes the following functions:

Displays the virtual machine process and its configuration, environment information (jps, jinfo).

Monitoring the application's CPU, GC, heap, method area (1.7 or earlier), metaspace (JDK1.8 and later), and thread information, which is equivalent to jmap,jstat,jstack.

Dump and Analysis Heap dump Snapshot (jmap,jhat).

The running performance of the program at the method level is analyzed to find out the method that is called the most and takes the longest time to run.

Offline program snapshot: collect the runtime configuration, thread dump, memory dump and other information of the program to establish a snapshot

The function on the interface is mainly divided into several modules, which are overview, monitoring, thread and sampler.

3.2.1 Overview

The overview is equivalent to jps and jinfo in the java command line tool, showing the process and its configuration, system properties, startup parameters, etc., similar to jconsole's "VM profile". As shown below:

3.2.2 Monitoring

This function is equivalent to the "overview" function of jconsole, and also graphically displays CPU, heap changes, thread changes and load classes, but it has a function that can remotely dump out of the heap to dump snapshots (equivalent to jmap-dump:file=./heap.hprof PID), and the file storage location will be selected when dump.

Dump out of the heap snapshot, we can manually download the file, and then use its "load snapshot" function to load into jvisualvm (when loading needs to select the file type is "hprof" type), further analyze the memory situation of the heap. After loading, it will include summary information, class and instance memory usage. Double-click a class to see the specific number of instances. If you find that some classes have a large number of instances or occupy a high amount of memory, you can know where the problem lies. As follows:

3.2.3 Thread

This function is equivalent to the "threading" function of jconsole, but it is richer, it shows the running status and running time of each thread graphically, and at the same time, it can also carry out remote thread dump, which is actually the jstack-l function. After dump comes out, it will be displayed directly in the interface. As follows:

3.2.4 Sampler

Sampler is a unique function of jvisualvm, can sample CPU and memory display, memory information, thread information, can be very convenient to focus on analysis of a certain period of time data changes (can display in a hierarchical way down to the method execution time, class memory usage, etc.), but also provides the implementation of GC, memory dump and thread dump functions. As follows:

4 Summary

With two visualization tools, jconsole and jvisualvm, we can reduce the input of command line and monitor the memory, thread, CPU and other information of java application in a more convenient and intuitive way. It is a good helper to deal with Java online problems. However, it is important to note that before using these two tools, we still need to accumulate some knowledge about the running mechanism and threads of JVM,Java programs.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report