忽略来自其他类的System.exit() [英] Ignore System.exit() from other class
本文介绍了忽略来自其他类的System.exit()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于下面的课程,
public class ClassOne {
public static void main(String... args) {
System.exit(1);
}
}
下面的类也会被销毁,假设那里在调用ClassOne.main之后还有其他事情要做。
The following class will be destroyed as well, assuming there are other things to do after ClassOne.main is invoked.
public class ClassTwo {
public static void main(String... args) {
ClassOne.main(args);
Thread.sleep(30000);
}
}
有没有办法忽略System.exit( 1); ClassTwo中ClassOne的调用?
Is there a way to ignore the System.exit(1); of ClassOne in ClassTwo's invocation?
推荐答案
你不能忽视本身,但你可以防止它通过SecurityManager终止JVM。
查看这个问题详细代码示例。
You can't ignore it per se, but you can prevent it from terminating the JVM via SecurityManager. Take a look at this question for detailed code example.
这篇关于忽略来自其他类的System.exit()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文