Is there a way to ensure that the entire Java process will exit if there is a Hotspot crash?
We are hosting a native library in a remote Windows Java process (java.exe), for purposes of process isolation. However, we have discovered that even when there is a hotspot crash, although the main thread "dies" with a hotspot crash, the process itself does not die. We have to kill it in Task Manager.
We think this may be because the native library itself creates its own threads which are keeping the process alive.
We want the entire Java process to die if there is a hotspot crash.
Our current work around is to have another thread which is reading the output of the spawned process (we have to read the console output anyway to stop the process from blocking). We modified it to also look explicitly for a VM crash:
private static String HOTSPOT_CRASH = "# A fatal error has been detected by the Java Runtime Environment";
public void run() {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
do {
line = reader.readLine();
if (line != null) {
logger.info(prefix + ": " + line);
}
if(line.contains(HOTSPOT_CRASH)) {
logger.error(String.format("FATAL Hotspot crash detected. Killing child process '%s'...", hostProcess));
hostProcess.destroy();
}
} while (line != null);
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
But this is a hack: If the JVM knows enough to log out that there's been a crash, it would be much better if it could be told to terminate the current process too.
Is there a way do do this? Ideally it would be a command line option to the JVM.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)