Stopping a parallel java task with ant

我只是一个虾纸丫 提交于 2019-12-21 04:00:16

问题


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?


回答1:


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>

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

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

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.



来源:https://stackoverflow.com/questions/2299432/stopping-a-parallel-java-task-with-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!