How to listen for OutOfMemoryError and exit the JVM

rellocs wood :

Is there a way to build a global OutOfMemoryError Listener for my Java app?

I want to stop the JVM gracefully (try-catch is not an option) on OOM.

Jigar Joshi :

You can use JVM option

-XX:OnOutOfMemoryError="<cmd args>; <cmd args>"

and execute command of your choice

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=435583&siteId=1