ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Conor MacNeill <co...@apache.org>
Subject Re: wait for background thread
Date Tue, 26 Jul 2005 23:37:26 GMT
Patrick Martin wrote:
> Hi,
> 
> The idea is actually to do that entirely in java. It's for a task I
> want to share, so I'd like to avoid asking users to call a waitfor...
> 
> Basically, I'd like to see how to make the forget task work in
> non-daemon mode (ie, ant should not terminate until the background
> thread finishes). The <forget> task sources are available here::
> http://cvs.sourceforge.net/viewcvs.py/ant-contrib/ant-contrib/src/net/sf/antcontrib/process/ForgetTask.java?rev=1.3&view=markup
> 
> I actually don't understand why ant does not wait for the end of the
> thread. Does ant automatically terminates all underlying running
> threads when it exits? Is that something that changed in a recent
> release of ant?
> 

System.exit() doesn't wait for anything :-). Ant has always been this way.

You'll need to do a little work along these lines:

1. Store the threads created by your task container in a static
collection. You'll probably want to index them by the project instance.

2. Hook your task into the project's events. i.e. declare your task as a
build listener and wait for the buildFinished() event method to be called.

3. In that event method, join to each of the background threads you
stored in the static collection for the project instance that is ending.
You can get the instance from the event. Remove the thread reference
from the collection as you do so.

Conor

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message