Get the App
SLTechnology News&Howtos  ›  Development  › 

How to enable garbage collection logs in Java

Shulou Source: shulou.com Published: 2022-06-01 11:48:07 10月24日 Update

This article mainly explains how to enable garbage collection logs in Java. Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "How to enable garbage collection logs in Java"!

Enable GC logging

GC Logging can be enabled by passing the system properties mentioned below during application startup

Java 8:

The following are system properties supported by all Java versions prior to JDK 8.

-XX:+PrintGCDetails -Xloggc: Example: -XX:+PrintGCDetails-Xloggc:/opt/tmp/myapp-gc.log

From Java 9:

The following are system properties supported by all Java versions starting with JDK 9.

-Xlog:gc*:file= Example: -Xlog:gc*:file=/opt/tmp/myapp-gc.log How to parse GC logs?

Here is an example GC log generated when passing the above system attributes:

GC logs are informative, but understanding GC logs is not easy. There is not enough documentation to explain the GC log format. Most importantly, GC log formats are not standardized. It varies by JVM vendor (Oracle, IBM, HP, Azul, etc.), Java version (1.4, 5, 6, 7, 8, 9), GC algorithm (serial, parallel, CMS, G1, Shenandoah), GC system attributes (-XX:+PrintGC, -XX: +PrintGCDetails, -XX: + PrintGCDateStamps, -XX:+PrintHeapAtGC...). Based on this arrangement, there are easily over 60 different GC log formats.

Therefore, GC log analysis tools such as GCeasy and HPJmeter are highly recommended when analyzing GC logs. These tools parse GC logs and generate excellent graphical visualizations of data, report key performance metrics, and other useful metrics.

At this point, I believe that everyone has a deeper understanding of "how to enable garbage collection logs in Java," so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Tags: Logs properties systems garbage formats versions analysis examples content tools metrics learning support generation different practical deeper important vendors information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology NVidia Redmi OPPO Reno vpn