if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) {
return;
}
try {
ProcessDestroyer processDestroyer = new ProcessDestroyer();
Process process =
Runtime.getRuntime().exec(
"java -cp "
+ System.getProperty("java.class.path")
+ " "
+ getClass().getName());
assertFalse("Not registered as shutdown hook",
processDestroyer.isAddedAsShutdownHook());
processDestroyer.add(process);
assertTrue("Registered as shutdown hook",
processDestroyer.isAddedAsShutdownHook());
try {
process.destroy();
} finally {
processDestroyer.remove(process);
}
assertFalse("Not registered as shutdown hook",
processDestroyer.isAddedAsShutdownHook());
} catch (IOException e) {
e.printStackTrace();
}