Modern Collectors: G1, ZGC, and Shenandoah
G1 is a region-based collector designed to balance throughput and pause-time goals. ZGC and Shenandoah emphasize very low pause times through highly concurrent collection techniques.
The correct collector depends on workload, heap size, latency objectives, JVM version, and operational constraints.
java -XX:+UseG1GC -Xms2g -Xmx2g -jar app.jar
For modern JVMs, use the defaults and tuning guidance for the specific JDK release before adding many flags.
Avoid cargo-cult JVM flags
GC flags are version- and workload-sensitive. Measure first and consult documentation for the exact JDK release.
Key Takeaways
- G1 is a common general-purpose collector.
- ZGC and Shenandoah target very low pause behavior.
- Collector tuning must be based on the actual JDK version and workload.