在一个有很多关闭操作的高并发程序中,想知道如何设置退出代码而不过早地调用System.exit()? 可以设置“在其他所有事情完成时执行此代码”方法? 但我真的只是想过早地设置退出代码。
In a highly concurrent program with lots of shutdown operations, wondering how to set the exit code without prematurely calling System.exit()? Possible to set an "execute this code when everything else is done" method? but I'd really just like to prematurely set the exit code.
最满意答案
如果我正确理解你想要的是以某种方式保留退出码,请运行一些方法,然后用预定义的退出码调用System.exit 。 国际海事组织你应该做的是使用关闭挂钩代替。 也就是说,您的代码将在JVM关闭之前运行,并且(如果我正确地获得了您的要求)将会得到与简单编码实现相同的结果(即不是使用状态变量和不寻常的编码逻辑来实现您正在尝试执行的操作等) )
If I understand correctly what you want is to somehow keep the exit code, run some methods and then call System.exit with the pre-decided exit code. IMO what you should do is use Shutdown hooks instead. I.e. your code will run before the JVM shuts down and (if I got your requirement correctly) will have the same result with a straightforward coding implementation (i.e. instead of using using state variable and unusual coding logic to achieve what you are trying to do etc)
更多推荐
发布评论