One, foreword

JVisualVM is a Java virtual machine monitoring tool, if you need to monitor the JVM performance can use this tool

Using this tool, you can monitor the GC process of the Java Virtual Machine

So, how do you download such a powerful tool?

This tool comes with JDK1.6 and is located in the bin directory of your JDK

If you install JDK by default, you will see your JDK version on disk C, in the Java directory of Program Files. Click in and open the folder “bin” to see the software

Second, start JVisualVM

Start method:

1. Go to the bin directory of the JDK installation directory and double-click to open the program

2. Menu key +R, enter CMD into command line mode, enter the commandjvisualvmStart the program. Note: if using the command line to start the software, the command box can not be closed oh, if closed JVisualVM will also be closed, remember!!



After starting the program, enter the interface, this is the use of JVisualVM interface

Three, install the plug-in

Before using it, we need to install a plug-in to better observe the performance of the virtual machine. Click Tools – Plug-ins at the top

Select Download from the available plugins to install a Visual GC plug-in

An error is usually reported because the default link has been transferred and you need to change the default link in the Settings

Click Settings, Edit, and change the URL

So what do we put in the URL? Determine your JDK version number and use the following link to view the URL

To confirm the version number, click Menu +R, execute CMD, and type java-version to check your version number

For example, mine is 201

It will be on this website: https://visualvm.github.io/pl… Find the address of your version number and copy the URL to the Settings

For example, mine is 201 of JDK8, so it should be between 131 and 291, so I will copy the following line of blue URLs into the set customizer

Then you can download the plug-in you want

Then reboot and you’ll see the Visual GC option

Four, the use of

So let me start with a program that doesn’t stop

So I’m going to keep putting out 1, so it’s an infinite loop, so let’s go back to GC

First observation

Watch after a few seconds

After I stop the program and take a final look, the Java program Test on the left is gone and the GC on the right is stopped

It can be seen that the GC time refers to the number of GC occurrences. In the figure, there are 233 GC occurrences, which takes 276.256ms. In the Eden section, there are also 223 GC occurrences. The time spent was also 276.256ms. Obviously, all GC occurred in Eden area, and 0 GC occurred in the Old age area, and the cost was 0s.

This is just a normal loop that doesn’t take much work, so it doesn’t take up much memory. There aren’t many GC’s going on, and there’s no need for old age GC at all

The progress chart on the right shows the memory usage. When the color block reaches the top, the memory is full. At this time, a GC is needed, and the memory occupation is pushed to the next region

In addition to detecting garbage collection in the Java virtual machine, you can also monitor the CPU usage of the Java program, threads, and so on.

When we develop other programs, we may need to optimize the program, we need to combine these indicators to analyze, determine the optimization method. For example, the CPU utilization rate is always very low, which indicates that the CPU can use a relatively large amount of memory, and other consumption can be appropriately reduced, and CPU consumption can be increased to improve efficiency, etc

Of course, in addition to all the performance monitoring and GC process viewing I mentioned, there are other features you can use, such as performance risk, observing the performance of processes, and so on

Finally, some people may ask, what if the execution of the program is not an infinite loop, but a normal output. If you’re executing something that’s going to stop when it’s done, let’s say I’m going to take out the loop condition and stop it when it’s only executed once



Click Run and return to JVisualVM to see the results, but JVisualVM doesn’t show the Java process or just flashes by. This is because JVisualVM can only monitor the state of a Java program in real time. Because the program that has been changed ends after executing the output, JVisualVM has no way to monitor the state of the program. It can still be seen after you have stopped the program, because you have turned on the monitoring of the program before stopping. Shows the state of the last moment before the stop



Today’s share is over, I feel I have taken a small step forward, like this article small partners can point a like or leave a comment to support oh