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.
Asked
Active
Viewed 2,616 times
5

shaiis.com
- 244
- 4
- 10
1 Answers
4
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.)

Stephen C
- 698,415
- 94
- 811
- 1,216
-
1I combined these two JVM args, your assumption is not fully correct, The heap dump creation parallel to "On..." command, in my case the kill happened before dump is fully created, the death of the JVM in the middle of dump creation causing the `hprof` to be corrupted. – shaiis.com Mar 05 '12 at 09:48
-
OK, so the Oracle page is misleading. But you should still be able to work with that behavior to get the desired behavior. – Stephen C Mar 05 '12 at 22:47
-
@shaiis.com did this solution work? Do these 2 parameters work together correctly? – A_C Dec 26 '18 at 12:54