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 analyze the principle of Java garbage collection mechanism

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article shows you how to carry out the principle analysis of Java garbage collection mechanism, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Java garbage collection monitoring and analysis tool

Java VisualVM

Java VisualVM is provided free of charge when Java SE SDK is installed. Take a look at the / bin directory under your Java JDK installation directory, Javajdk1.8.0bin. Jvisualvm is one of many other tools in this directory, including javac and java tools.

Java VisualVM provides a visual display of information for running Java applications. It is an integrated package of many tools, such as tools JConsole,jstat,jinfo,jstack and jmap, which are now part of Java VisualVM.

Java VisualVM can be used to-generate and analyze dump for heap memory-observe and manipulate MBeans-monitor garbage collection-memory and CPU performance analysis

Launch VisualVM

Jvisualvm is already included in the bin directory of JDK. If you set the environment variable path, you can run jvisualvm directly on the command line. The following startup interface will appear

Install the Visual GC plug-in

We need to install the visual GC plug-in to have the beautiful and valuable visual feel of a heap Java GC thread. Click tools-> plug-ins-> available plug-ins-> Visual GC in the launch screen above

(for some reason, this picture is unsuccessful. Only attach the outer link address to read it. I'm sorry.)

Install.

Monitoring GC

You can now monitor the garbage collection process. Open your Java application and Java VisualVM will automatically detect and display it on the interface. Under the "Local" node of the "applications" panel on the left, all locally running Java applications are listed.

Java VisualVM itself is a Java application, so it is listed itself. For the purpose of this article, we will monitor the GC process of the VisualVM application itself.

Double-click the VisualVM icon under the Local node.

In this way, the application's monitoring panel opens on the right. There are multiple tabs on the panel, each showing aspects related to application performance. Since we are now mainly focused on "Visual GC", so, click on it.

The image above shows the memory space used by Old,Eden,S0,S1. The following chart shows the details of each section requesting and releasing memory. It keeps updating at a set refresh rate.

The picture above shows a running program. When memory leaks or abnormal operations occur, you can clearly see it in the graphics itself. At least we can know that there are problems related to object memory allocation and garbage collection in the program. Then using other tags such as the information provided in "Threads" and Thread Dump, we can narrow down the scope of the problem.

In the "Monitor" tab, we can see an overview of memory usage developed in a timeline. There is a "perform garbage collection" button to call the garbage collection process.

In the "Sampler" tab, we can start memory and CPU analysis. The sampler displays the usage of each instance in real time. It can help determine exactly where the performance problem occurs.

The above content is how to analyze the principle of Java garbage collection mechanism. have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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