ProLesson 10.5Advanced4 min readUpdated 30 October 2026
Garbage collectors: G1, ZGC, Parallel and Serial
The main HotSpot garbage collectors, what each optimises for, how to choose, and the JVM options you'll actually use.
The JVM ships with several garbage collectors. Each makes a different trade-off between throughput (how much CPU time goes to your code rather than GC), latency (how long pauses are) and memory footprint.
01The collectors at a glance
| Collector | Flag | Optimised for | Pauses | Typical use |
|---|---|---|---|---|
| Serial | -XX:+UseSerialGC | Tiny footprint | Stop-the-world, single thread | Small heaps, small containers, CLI tools |
| Parallel | -XX:+UseParallelGC | Maximum throughput | Stop-the-world, many threads | Batch jobs where pauses don't matter |
| G1 (default) | -XX:+UseG1GC | A balance of throughput and predictable pauses | Short, with a target pause time | Most server applications |
| ZGC | -XX:+UseZGC | Very low latency | Typically under a millisecond, mostly concurrent | Large heaps, latency-sensitive services |
| Shenandoah | -XX:+UseShenandoahGC | Low latency | Mostly concurrent | Available in many OpenJDK builds |
G1 has been the default since Java 9, on machines the JVM considers "server class". On very small machines (one CPU or little memory) the JVM may pick Serial instead.
Loading the rest of the lesson…