0Pricing
Java Academy · Lesson

GC Algorithms: Serial, G1, ZGC, Shenandoah

Compare GC pause characteristics and throughput trade-offs across modern JVM collectors.

Choosing a GC Algorithm

The JVM ships with multiple GC algorithms, each optimized for different workloads. Choosing the right one depends on heap size, latency requirements, and throughput goals.

// Enable GC algorithms:
// -XX:+UseSerialGC
// -XX:+UseParallelGC
// -XX:+UseG1GC       (default since Java 9)
// -XX:+UseZGC        (Java 15+ production)
// -XX:+UseShenandoahGC (Red Hat / OpenJDK builds)

Serial GC

Serial GC uses a single thread for collection. All application threads stop during GC ("stop-the-world"). Suitable only for small heaps or single-CPU environments like embedded systems.

// Use:
// java -XX:+UseSerialGC -Xmx256m MyApp
// Pauses: long (proportional to heap size)
// Throughput: low
// Best for: CLI tools, small heaps < 100 MB

All lessons in this course

  1. JVM Heap Regions and Object Lifecycle
  2. GC Algorithms: Serial, G1, ZGC, Shenandoah
  3. Detecting and Fixing Memory Leaks
  4. GC Tuning Flags and JVisualVM Profiling
← Back to Java Academy