This question already has an answer here:
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.
Oracle's GC ergonomics guide covers options for both thresholds.
GCTimeLimit
andGCHeapFreeLimit
. Lowering the former and increasing the latter should result in OOMs occuring sooner.