Rate This Document
Findability
Accuracy
Completeness
Readability

GCs Caused by System.gc()

Prerequisites

  • The server and OS are running properly.
  • An SSH remote login tool has been installed on the local PC.
  • The Java program (demo) to be tuned is running on the target server.

Procedure

  1. Perform profiling analysis on the target program.
  2. Switch to the GC tab page.

    Invoke http://IP_address:9118/gctest/systemgc to trigger a GC event.

    Figure 1 GC tab page
    Figure 2 Tuning Suggestions

    It is found that some GC events are caused by the calling of the System.gc() function. In this case, read the precautions for using the System.gc() function in the tuning suggestions.

  3. Enable the startup parameters based on the tuning suggestions.

    Enable the startup parameter -XX:+ExplicitGCInvokesConcurrent.

    Figure 3 Overview
    Figure 4 GC tab page

    It is found that the GC garbage collector caused by the System.gc() function changes from Old to Young, relieving the garbage collection pressure.

  4. Summarize the tuning.

    Exercise caution when using the System.gc() function in the program. If the function is not used in the program and the dependent framework is not used, you can enable the -XX:+DisableExplicitGC parameter to disable the function. If the program or dependency framework needs to use this function, enable the -XX:+ExplicitGCInvokesConcurrent parameter to tune the GC mode.