Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OutOfMemoryError - how to kill the JVM after the hprof created

I want my java to exit when catching OutOfMemoryError, I'm using the -XX:+HeapDumpOnOutOfMemoryError to dump hprof file.
I can't use kill -9 <pid> because the JVM needs to be up while dumping the hprof file, is there any way to stop the JVM after the hprof file created?

To be clear I'm using Sun's JVM version 6.

like image 869
shaiis.com Avatar asked Oct 08 '22 12:10

shaiis.com


1 Answers

This page seems to imply that you can combine -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError="kill -9 %p"

Presumably, the heap dump is created before the "On..." command is run. (It should be easy to throw together something to test this out.)

like image 90
Stephen C Avatar answered Oct 12 '22 10:10

Stephen C