使用 ant 停止并行 Java 任务 [英] Stopping a parallel java task with ant

查看:25
本文介绍了使用 ant 停止并行 Java 任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发两个在具有典型服务器/客户端关系的单独 VM 中运行的 Java 程序.使用 ant 的并行/顺序任务,我已经能够让 ant 运行服务器,然后运行客户端.我现在想要这样,当客户端进程停止时,ant 会杀死服务器.我已经看到使用针对特定服务器应用程序(如 TomCat)的自定义 ant 任务完成了这项工作,是否存在使用通用 Java 进程执行此操作的任何方法?

I am developing two java programs that run in separate VM's that have a typical server/client relationship. Using ant's parallel/sequential tasks I've been able to get ant to run the server and then the client. I would now like it so that when the client process has stopped, ant kills the server. I've seen this done with custom ant tasks for specific server applications (like TomCat), does any method exist for doing this with generic java processes?

推荐答案

由于您正在开发服务器应用程序,因此您可以让它侦听关闭"命令.然后你可以让 ant 在客户端退出时向它发送关闭命令,例如:

Since you are developing the server application, you can have it listen for a "shutdown" command. Then you can have ant send it the shutdown command when the client exits, something like:

<parallel>
    <server .../>
    <sequential>
        <client ... />
        <!-- client has finished,  send stop command to server -->
    </sequential>
</parallel>

另一个可能对您有用的选项是在 daemons 元素内启动服务器.

Another option which may work for you is to start the server inside a daemons element.

<parallel>
    <daemons>
        <server .../>
    </daemons>
    <sequential>
        <client ... />
    </sequential>
</parallel>

这将使服务器在守护线程中运行,这不会阻止 ant 完成.当 ant 停止时,所有守护线程,包括您的服务器,都将被终止.

This will make the server run in a daemon thread, which will not prevent ant from completing. When ant stops, all daemon threads, including your server, will be terminated.

这篇关于使用 ant 停止并行 Java 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆