OpenJDKを使用している場合は、-XX:OnOutOfMemoryErrorオプションで設定したコマンドを実行するときには必ず確認できます。
OpenJDKのソースコードから取得したコード。参照:debug.cpp
void report_java_out_of_memory(const char* message) {
static jint out_of_memory_reported = 0;
// A number of threads may attempt to report OutOfMemoryError at around the
// same time. To avoid dumping the heap or executing the data collection
// commands multiple times we just do it once when the first threads reports
// the error.
if (Atomic::cmpxchg(1, &out_of_memory_reported, 0) == 0) {
// create heap dump before OnOutOfMemoryError commands are executed
if (HeapDumpOnOutOfMemoryError) {
tty->print_cr("java.lang.OutOfMemoryError: %s", message);
HeapDumper::dump_heap_from_oome();
}
if (OnOutOfMemoryError && OnOutOfMemoryError[0]) {
VMError err(message);
err.report_java_out_of_memory();
}
}
}
念のため簡単な説明:すべてのチェックの
- まずHeapDumpOnOutOfMemoryErrorオプションが設定された場合。あなたはOpenJDKのを使用している場合OnOutOfMemoryErrorオプションが設定されたのであれば
)を実行report_java_out_of_memory(、Sencondly
)(dump_heap_from_oomeを実行している場合は、確かにあなたのプロセスは、メモリをダンプしてから終了します。
キルをしないでください。トップレベルのtry-catchを持って、syste.exitを実行します。 –