Skip to content

GC Algorithms at a Glance

A quick field guide to the collectors EasyGC recognizes, and when to pick which.

The collectors

CollectorFlagStrategyTypical pauseGood for
Serial-XX:+UseSerialGCSingle-threaded, generational100 ms – secondsSmall heaps, single-core containers, batch tools
Parallel-XX:+UseParallelGCMulti-threaded, generational50 ms – secondsMax throughput, batch/analytics, latency-tolerant
CMS-XX:+UseConcMarkSweepGCMostly concurrent old-gen10 – 100 msLegacy low-latency services (removed in Java 14)
G1-XX:+UseG1GCRegion-based, concurrent marking10 – 200 ms (targeted)Default since Java 9; balanced throughput/latency
ZGC-XX:+UseZGCConcurrent, colored pointers< 1 msHuge heaps, strict SLOs (Java 15+)
Shenandoah-XX:+UseShenandoahGCConcurrent, forwarding pointers< 10 msLow latency on OpenJDK builds

How to choose

  1. Default choice: G1. It is the JDK default for a reason — predictable pauses with decent throughput.
  2. Throughput above all (batch jobs, data pipelines)? Parallel GC gives the best raw throughput at the cost of longer pauses.
  3. Strict latency SLO (p99 < 50 ms) with a large heap? ZGC or Shenandoah keep pauses in the sub-10 ms range regardless of heap size.
  4. Tiny container (≤ 512 MB)? Serial GC often beats everything — no threads to coordinate.

Key tuning knobs

KnobMeaning
-Xms / -XmxInitial / maximum heap size. Setting them equal avoids resize pauses.
-Xmn / -XX:NewRatioYoung generation size — the main lever on GC frequency.
-XX:MaxGCPauseMillisG1 pause goal (default 200 ms). Don't set it unrealistically low.
-XX:MaxMetaspaceSizeCap for class metadata — prevents metaspace-driven Full GCs.
-XX:+DisableExplicitGCIgnore System.gc() calls (check Direct ByteBuffers first!).
-XX:G1HeapRegionSizeG1 region size — raise it if humongous allocations dominate.

Reading the signals in your report

  • Allocation Failure young GCs are normal and healthy.
  • System.gc() causes are almost always worth removing.
  • Metadata GC Threshold / Metaspace causes point at classloader churn.
  • G1 Humongous Allocation means objects larger than half a region — refactor or enlarge regions.
  • A steadily climbing after-GC heap means leaked objects survived collection — see Understanding the Report.