本文介绍了如何杀死 Ant 启动的失控 Java 进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从 ant 脚本启动一个分叉的 java 进程并杀死 ant 进程,它不会杀死 java 进程.无论是从 IDE 还是从命令行运行,都是如此.

If I start a forked java process from an ant script and kill the ant process, it does not kill the java process. This is the case whether running it from the IDE or from the command line.

<target name="myTarget" >
  <java classname="path.to.MyClass"
        fork="yes"
        failonerror="true"
        maxmemory="128M">
    <classpath refid="run" />
  </java>
</target>

有没有办法把这些链接起来,这样杀死ant进程就会杀死java进程?

Is there a way to link these, so that killing the ant process will kill the java process?

我看过以下问答 - 但这似乎专注于如何手动杀死java进程.我不想这样做,因为我有许多其他 Java 应用程序正在运行,并且在 TaskManager 中找到要杀死的正确 java.exe 进程并不总是很简单.

I've seen the following Q&A - but this seems to focus on how to kill the java process manually. I don't want to do this, because I have a number of other java applications running, and finding the right java.exe process to kill in TaskManager is not always straight forward.

推荐答案

不幸的是,这似乎是一个长期存在的已知问题.

Unfortunately, it appears that this is a long-standing and known issue.

当 Ant 任务终止时,不会触发分叉的 Java 进程关闭挂钩.(这似乎是自 Java 1.4 (!) 以来的一个问题)

When the Ant task is terminated, the forked Java process shutdown hooks are not fired. (This seems to have been an issue since Java 1.4 (!))

供参考:

这篇关于如何杀死 Ant 启动的失控 Java 进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 01:06