JVM不会终止(JVM won't terminate)

编程入门 行业动态 更新时间:2024-10-25 17:24:22
JVM不会终止(JVM won't terminate)

我有一个简单的测试运行的一些中等复杂性代码不会终止,即主方法完成但过程不会死。

这是代码的一个纲要(这里太长了,无法粘贴):

ProcessBuilder用于创建一堆子进程。 它们都正常死亡(如果你能相信VisualVM)。 我们使用log4j。 主算法在FutureTask内run , run后来调用get 。 我们没有明确使用RMI,即使线程列表似乎是这样建议的。

显然,我可以调用System.exit(0) ,但我想知道这里有什么不妥。 我无法生成最小的失败示例。 另外,我无法从线程列表中找出明显的罪魁祸首; 也许你可以?

编辑:请参阅此处获取线程转储。

I have a simple test run of some medium-complexity code that won't terminate, i.e. the main method finishes but the process does not die.

Here is a rundown of the code (which is too long to be pasted here):

ProcessBuilder is used to create a bunch of subprocesses. They all die properly (if you can believe VisualVM). We use log4j. The main algorithm runs inside a FutureTask on which run and later get are called. We don't explicitly use RMI, even though the list of threads seems to suggest so.

Obviously, I can call System.exit(0), but I'd like to know what is amiss here. I have not been able to produce a minimum failing example. Also, I can not identify an obvious culprit from the thread list; maybe you can?

Edit: See here for a thread dump.

最满意答案

蝎子引导我找到正确的答案:

RMI Reaper类似于远程对象的垃圾收集器,例如UnicastRemoteObject的(子类)实例。 它是一个非守护程序线程,因此如果仍有导出的对象无法清除,则会阻止JVM终止。

您可以通过将远程对象传递给UnicastRemoteObject.unexportObject(., true)来明确强制清除远程对象。 如果对所有先前导出的对象执行此操作,则RMI Reaper终止,JVM可以自由关闭。

Scorpion lead me to the right answer:

RMI Reaper is something like a garbage collector for remote objects, e.g. instances of (subclasses of) UnicastRemoteObject. It is a non-daemon thread and therefore blocks JVM termination if there are still exported objects which can not be cleaned up.

You can explicity force remote objects to be cleaned up in this sense by passing them to UnicastRemoteObject.unexportObject(., true). If you do this on all previously exported objects, RMI Reaper terminates and JVM is free to shut down.

更多推荐

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

发布评论

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

>www.elefans.com

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