The Parallel Garbage Collector - Sip of Java

The Parallel Garbage Collector (GC), so named because it can utilize multiple threads for handling GC tasks, provides the highest throughput of GCs available on the OpenJDK. Let’s take a look at the Parallel GC in this article.

Using the Parallel GC

The Parallel GC can be enabled using the VM arguments -XX:+UseParallel GC. As mentioned, the Parallel GC provides the highest throughput of the GCs available on OpenJDK; Serial GC, G1 GC, and Z GC, but this does come at the cost of pause times and memory footprint. So consider those impacts when deciding to use the Parallel GC.

Tuning Parallel GC

There are many options for tuning Parallel GC; a few key options to consider are the following.

  • MaxPauseTimeMillis: This provides a hint to the GC that pause times should be less than the provided amount. No default value is set for this flag.

  • GCTimeRatio: This sets the ratio for the time spent between performing GC work and application work. The default value is set at 1 to 99.

  • Parallel GCThreads: This sets the number of threads that can be used for performing GC work. The default value is based on HotSpot ergonomics determined from available system resources. See the link below.

  • +UseStringDeduplication: In JDK 18, String deduplication was ported over from the G1 GC to Parallel GC. Enabling string deduplication can reduce memory footprint by about 10% but could impact pause times.

Additional Reading

Happy coding!