Problem Statement
You observe long GC pauses in production. Outline a pragmatic 4-step tuning approach before changing the collector.
Explanation
One: Measure first—enable GC logs and capture p99 latency and allocation rates. Two: Fix allocation hot spots—reduce temporary objects, reuse buffers, enable pooling only if profiling proves it. Three: Right-size the heap and young generation to match live-set and allocation rate. Four: Set realistic pause goals (e.g., G1 MaxGCPauseMillis) and re-measure. Only then consider switching collectors (e.g., to ZGC) if goals still aren’t met.
Practice Sets
This question appears in the following practice sets:
