Skip to main content
InterviewHubPRO
Section Overview
Q29

Question 29 of 50

Part 3: JVM Internals, Low-Latency Systems & Production Tuning (25 - 35)

58%
Java Core & JVM (50 Qs)•Part 3: JVM Internals, Low-Latency Systems & Production Tuning (25 - 35)

Compare G1GC, ZGC, and Shenandoah Garbage Collectors for high-throughput and low-latency systems?

senior LevelCode ExampleMemory Management

In Simple Words:

  • G1GC (Garbage-First): The default collector since Java 9. Divides the heap into equal regions (1MB-32MB). Balances throughput and latency with configurable pause targets (-XX:MaxGCPauseMillis=200). Suitable for heaps up to 32GB with acceptable 50ms-200ms pauses.
  • ZGC (Z Garbage Collector): Low-latency, scalable collector. Performs almost all phases (marking, relocation, reference processing) concurrently with application threads. Pauses are guaranteed under 1 millisecond, regardless of whether the heap is 16MB or 16 Terabytes!
  • Shenandoah: Ultra-low-latency collector developed by Red Hat. Performs concurrent evacuation using Brooks Pointers / Load Reference Barriers to maintain low pauses.
bash
# Enable Generational ZGC in Java 21+ for production:
java -XX:+UseZGC -XX:+ZGenerational -Xmx32g -jar app.jar