Why it matters

GC pause time dominates JVM p99 latency in most applications. Choosing the right collector and tuning it can drop p99 by orders of magnitude. This is worth learning.

Advertisement

The architecture

Serial GC (-XX:+UseSerialGC): one thread does all collection. Simple, low overhead, but pauses grow with heap size. Good for heaps under 100 MB.

Parallel GC (-XX:+UseParallelGC): parallelizes young + old collection. Maximizes throughput at the cost of pause time. Default in older Java versions for large heaps.

GC algorithm spectrumParallel GCthroughputG1 GCpredictable pausesZGC / Shenandoahsub-ms pausesThroughput vs latency trade-off; modern default is G1 for most workloads
GC choice by workload.
Advertisement

How it works end to end

G1 GC (default in Java 11+): heap divided into small regions, collected incrementally. Pause target configurable via -XX:MaxGCPauseMillis. Balances throughput and latency. Good for heaps 4 GB to 32 GB.

ZGC (-XX:+UseZGC): concurrent collector targeting sub-10ms pauses even on huge heaps (multi-TB). Uses colored pointers and load barriers. Great for latency-sensitive services.

Shenandoah (-XX:+UseShenandoahGC): another concurrent collector similar to ZGC. Ships with OpenJDK.