How can I OOM sooner in excessive GC? [duplicate]

2019-04-09 14:22发布

问题:

This question already has an answer here:

  • Adjusting GC Overhead Exceeded parameters 1 answer

Occasionally my JVM runs out of memory, but rather then OOMing which I can recover from (or heapDumpOnOOM and debug) it tends to thrash in GC for hours before throwing out of memory. This is essentially the same as the (unanswered) question: How can I configure the Java GC Overhead Limit? But I suspect the answer is you can't tune the 98%/2% thresholds, so I'm asking of any way to achieve similar effect. notice excessive GC, and preferably cause OOM, or kill the JVM or such.

回答1:

Oracle's GC ergonomics guide covers options for both thresholds. GCTimeLimit and GCHeapFreeLimit. Lowering the former and increasing the latter should result in OOMs occuring sooner.