[英]JVM won't terminate
I have a simple test run of some medium-complexity code that won't terminate, ie 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. ProcessBuilder
用于创建一堆子进程。 They all die properly (if you can believe VisualVM). 它们都正常死亡(如果你能相信VisualVM)。 FutureTask
on which run
and later get
are called. 主算法在FutureTask
内run
, run
后来调用get
。 Obviously, I can call System.exit(0)
, but I'd like to know what is amiss here. 显然,我可以调用System.exit(0)
,但我想知道这里有什么不妥。 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? 也许你可以?
Scorpion lead me to the right answer: 蝎子引导我找到正确的答案:
RMI Reaper
is something like a garbage collector for remote objects, eg instances of (subclasses of) UnicastRemoteObject
. RMI Reaper
类似于远程对象的垃圾收集器,例如UnicastRemoteObject
的(子类)实例。 It is a non-daemon thread and therefore blocks JVM termination if there are still exported objects which can not be cleaned up. 它是一个非守护程序线程,因此如果仍有导出的对象无法清除,则会阻止JVM终止。
You can explicity force remote objects to be cleaned up in this sense by passing them to UnicastRemoteObject.unexportObject(., true)
. 您可以通过将远程对象传递给UnicastRemoteObject.unexportObject(., true)
来明确强制清除远程对象。 If you do this on all previously exported objects, RMI Reaper
terminates and JVM is free to shut down. 如果对所有先前导出的对象执行此操作,则RMI Reaper
终止,JVM可以自由关闭。
You mention FutureTask. 你提到FutureTask。 The first thing that comes to my mind is: are you using ExecutorService and forgetting to shut it down? 我想到的第一件事是:你使用ExecutorService并忘记关闭它吗?
The second thing that comes to my mind is: are you reading to the end all the streams from the process? 我想到的第二件事是:你是否正在阅读流程中的所有流? I worked with subprocesses long ago, and I don't remember exactly, but. 我很久以前就和子过程一起工作过,而且我记不清楚了。 I had problems similar to what you described, and by reading the streams to the end the problem would misteriously disappear! 我遇到的问题与你描述的类似,通过阅读流到最后,问题会大量消失!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.