停止与蚂蚁并行java任务 [英] Stopping a parallel java task with ant

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

问题描述

我开发一个单独的虚拟机具有典型的服务器/客户关系运行两个Java程序。使用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?

推荐答案

由于正在开发的服务器应用程序,你可以把它听到关机命令。然后你就可以有蚂蚁发送关机命令,当客户端退出,是这样的:

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>

这可能为你工作的另一个选项是启动里面的守护程序服务器元素。

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

这将会使服务器运行在一个守护线程,不会prevent蚂蚁无法完成。当蚂蚁停止,所有的守护线程,包括你的服务器,将被终止。

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.

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

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