Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stopping a parallel java task with ant

Tags:

java

client

ant

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?

like image 855
Sandro Avatar asked Feb 19 '10 20:02

Sandro


1 Answers

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.

like image 83
Jason Day Avatar answered Oct 20 '22 16:10

Jason Day