【发布时间】:2012-04-14 12:55:21
【问题描述】:
我有以下
System.setSecurityManager(new SecurityManager() {
@Override
public void checkExit(int status) {
super.checkExit(status);
//custom exception extends SecurityException
throw new SystemExitCalledException();
}
});
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
//never reaches here somehow...
//maybe some3rdPartyStaticMethod sets this, too?
}
});
try {
//this method spawns threads and some call System.exit().
some3rdPartyStaticMethod.invoke(null, new Object[]{args});
} catch (SystemExitCalledException e) {
//it never reaches here because
//SystemExitCalledException is thrown on different thread??
//
}
有没有办法防止 some3rdPartyStaticMethod 的派生线程的 System.exit() 调用停止 jvm?
【问题讨论】:
-
也许您可以使用 'SecurityManager' 将调用 'Shutdown.exit' 替换为 'SecurityException'。
标签: java multithreading jvm securitymanager system.exit