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 VisualVM of JDK to analyze the performance of Java programs

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces how to use JDK's own VisualVM for Java program performance analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

What is VisualVM?

VisualVM is a tool for Java program performance analysis that comes with JDK. It will be available after JDK installation. The name jvisualvm.exe can be found in the bin folder of the JDK installation directory.

To use VisualVM to analyze your application performance, you must first let VisualVM recognize your application. Eclipse has a plug-in called "VisualVM Launcher for Eclipse" that can help us do this.

Installation and configuration of Eclipse VisualVM Launcher

1. Download the VisualVM Launcher plug-in from the link below. When the download is complete, put it under the plugins folder of your local Eclipse folder.

Http://visualvm.java.net/eclipse-launcher.html

You can refer to my local Eclipse folder in the following picture. Note that after the plug-in is unzipped, there should be a file called site.xml.

two。 In Eclipse, click the menu "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 ready to install.

3. After installation, restart Eclipse, and you can see a new interface for VisualVM in Eclipse's option. We need to tell Eclipse the exact path to the executable file of the VisualVM that comes with our JDK. Here, you can specify it according to the path of JDK.

Note that JDK home should not be mistakenly specified as the path of JRE, otherwise Eclipse will also intimately pop up the error message: Error Starting VisualVM:You are running VisualVM using Java Runtime Environment (JRE).

Using VisualVM for performance testing

Right-click your Java project and select "Run as"-> "Run configuration" from the right-click menu to create a new application startup configuration.

Because we have successfully installed Eclipse VisualVM Launcher before, we find that there is an option for VisualVM Launch in addition to the Eclipse JDT launcher that comes with Eclipse.

two。 Suppose I have implemented a quick sort algorithm myself, and I want to test its performance.

First of all, I set a breakpoint where line 57 of the following code executes my quick sort algorithm.

Then start my Java application in debug mode using the Eclipse VisualVM Launcher-based application startup configuration created in the previous step.

The breakpoint was triggered so that VisualVM successfully identified my Java application. Click the Profiler tab:

Current status: profiling inactive.

Click the CPU button:

Profile is now active.

3. Go back to Eclipse and press F8 to end the execution of the application. As soon as the application is finished, VisualVM will immediately capture this event and pop up a window to inform us:

Click Yes to check out the performance evaluation and analysis report generated by VisualVM for us.

Thank you for reading this article carefully. I hope the article "how to use JDK's own VisualVM to analyze the performance of Java programs" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Development

Wechat

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

12
Report