What is VisualVM?
VisualVM is JDK own a tool for Java program performance analysis, JDK installed after there, in the JDK installation directory bin folder can find the name of jVisualVM. Exe.
To use VisualVM to analyze the performance of your application, you must first have VisualVM recognize your application. Eclipse has a plug-in called “VisualVM Launcher for Eclipse” that helps us do just that.
Installation and configuration of the Eclipse VisualVM Launcher
1. Download the VisualVM Launcher plug-in from the link below. Once the download is complete, place it in the plugins folder of your local Eclipse folder.
Visualvm.java.net/eclipse-lau…
You can refer to my local Eclipse folder below. Note that after the plug-in is unzipped, there should be a file called site.xml.
2. In Eclipse, go to “Help->Install New Software” and click “Local” to load the plug-in file downloaded in the first step.
The Plugin file has been successfully identified and is ready to install.
3. After the installation is complete, restart Eclipse and you can see a new VisualVM interface in Eclipse option. We need to tell Eclipse the exact path to the VisualVM executable that comes with our JDK. You can specify the JDK path here.
Error Starting VisualVM: Error Starting VisualVM: You are running VisualVM using Java Runtime Environment(JRE).
Use VisualVM for performance testing
Right-click on your Java project and choose “Run as” -> “Run Configuration” from the right-click menu to create a new application launch configuration.
Since we have successfully installed the Eclipse VisualVM Launcher, we now see an option for the VisualVM Launch in addition to the Eclipse JDT Launcher that comes with Eclipse.
2. Suppose I implemented a quicksort algorithm myself and wanted to test its performance.
First I set a breakpoint at line 57 of the code below where I execute my quicksort algorithm.
I then used the application Launcher configuration based on the Eclipse VisualVM Launcher created in the previous step to launch my Java application in debug mode.
The breakpoint fires, and VisualVM successfully recognizes my Java application. Click on the Profiler TAB:
Current status: Profiling Inactive.
Click the CPU button:
The Profile is now active.
3. Go back to Eclipse and press F8 to end the application. As soon as the application ends, VisualVM catches this event and pops up a window informing us:
Click Yes to view the performance profiling report VisualVM has produced for us.
For more of Jerry’s original technical articles, please follow the public account “Wang Zixi” or scan the following QR code: