尚未退出,请设置Java退出代码(Set Java exit code without exiting yet)

编程入门 行业动态 更新时间:2024-10-26 12:27:20
尚未退出,请设置Java退出代码(Set Java exit code without exiting yet)

在一个有很多关闭操作的高并发程序中,想知道如何设置退出代码而不过早地调用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)

更多推荐

本文发布于:2023-08-05 20:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1439230.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   Set   Java   exiting   code

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!