Java / Java 17 Garbage Collection Interview Questions
How do you configure G1 GC's pause time goal?
The pause-time goal is set with -XX:MaxGCPauseMillis=<n>, for example -XX:MaxGCPauseMillis=100 to ask G1 to try to keep pauses at or under 100ms. The default is 200ms.
It's important to understand this is a soft goal, not a hard guarantee - G1 uses it to decide how many regions to include in each collection (fewer regions per pause if the goal is tight), and under heavy allocation pressure or evacuation failures it can still exceed the target.
Setting the goal very low trades away throughput: G1 will do more frequent, smaller collections to stay under the target, which means more total GC cycles and often lower application throughput overall - so this flag is a throughput-versus-latency dial, not a free win.
More Related questions...