Full GC Every 10 Minutes: A JDK 21 Diagnostic Walkthrough from jstat to JFR to a Code Fix
Full GC stalls are a top production killer for any Java service, and the debugging path shown here uses only tools already in the JDK. The concrete lesson generalizes beyond this demo: unbounded static caches and large arrays are the usual suspects, and fixing them beats tuning the collector.
A report service on JDK 21 shows a classic production failure: P99 jumps from 80ms to 8 seconds, CPU stays flat, and the GC log shows Full GC every 10 minutes with pauses over 3 seconds. The root cause is a static ConcurrentHashMap that caches 20MB report arrays and never evicts them. Under G1, each 20MB byte[] is a Humongous object that goes straight to the old generation, and the cache's strong references make those regions impossible to reclaim.
The diagnostic sequence is entirely JDK built-in tools. jstat -gcutil shows old-generation usage pinned above 90% with Full GC count climbing. JFR recording via jcmd points allocation hot spots directly at the new byte[20MB] call. jmap -histo:live confirms byte arrays dominate the heap, and a heap dump with MAT traces the reference chain to the static field. The fix adds a scheduled cleaner that clears the cache every 24 hours and swaps put-if-absent logic to ConcurrentHashMap.computeIfAbsent.
JVM tuning advice covers three parameters: InitialRAMPercentage and MaxRAMPercentage for container-aware heap sizing, MaxGCPauseMillis=100 for G1's pause target, and HeapDumpOnOutOfMemoryError plus unified GC logging for incident forensics. A comparison of Parallel, G1, and ZGC ends with the practical rule: no collector rescues leaky code; caches need a bound or an expiration.
The diagnostic order matters more than any single tool: jstat narrows the generation, JFR finds the allocation site, jmap confirms the object type, and only then does the code fix become obvious.
A cache without an eviction policy is a time bomb regardless of the garbage collector; tuning collector parameters only postpones the inevitable and often makes pauses worse.
JFR being always-on in production is the single highest-leverage habit described; the 1% CPU cost is trivial compared to a 30-minute heap dump transfer.
The article's advice to avoid setting both -Xmx and MaxRAMPercentage is a reminder that container-aware JVM defaults have changed; blindly carrying old flags into Kubernetes breaks memory accounting.