What garbage collectors are available and how do you choose?
⚡
Quick Answer
G1 (default, balanced), ZGC/Shenandoah (low pause, large heaps), Parallel (throughput). Choose by pause vs throughput needs.
Detailed Answer
G1 balances pause and throughput for most services. For latency-sensitive apps with large heaps, ZGC or Shenandoah keep pauses sub-millisecond. Parallel GC maximizes throughput for batch jobs where pauses don't matter. Measure with GC logs before switching.
💡
Interview Tip
Match GC to the workload; measure with GC logs.
jvmgctuning