Java / Java 17 Garbage Collection Interview Questions
What is the difference between throughput and low-latency garbage collectors?
Throughput-oriented collectors aim to maximize the percentage of total time spent running application code versus doing GC work, generally by batching up collection work and accepting longer, less frequent pauses. Low-latency collectors instead aim to minimize the length of any individual pause, even if that means doing more total CPU work overall (via concurrent marking/relocation) to get there.
| Collector | Optimizes for | Typical pause behavior |
| Parallel GC | Throughput | Longer, less frequent pauses |
| G1 GC | Balanced | Configurable, moderate pauses |
| ZGC / Shenandoah | Low latency | Very short, heap-size-independent pauses |
Choosing between them is a workload decision, not a strictly better-or-worse one: a nightly batch ETL job usually cares about total runtime (throughput), while a request-serving API usually cares about P99 latency (low pause time), even at some throughput cost.
More Related questions...