On Fri, Jan 22, 2010 at 2:31 AM, David Blevins <[email protected]> wrote:

> In your test case you could construct a "CountDownLatch latch = new
> CountDownLatch(1)" and pass that instance to your asynchronous method so
> both the test case and the target method have a reference to the same latch.
>  The method will just call latch.await() which will cause the asynch thread
> to pause. Then in your test case you can test the 'isDone' logic on your
> future, then call latch.countDown() which will cause the asynch thread to
> resume and complete, then you can test your 'isDone' 'true' logic.  Best to
> call get() on the future before calling isDone() or isDone() could return
> false.

Yay! David, that's awesome. I've never looked at the j.u.concurrent
package at all, but with the trick I felt in love with it. Really
great.

p.s. I once tried to get the gist of it, but since I didn't have
enough understanding of the concurrency package I failed. Now, it's
way clearer. I think the JDK team should take your comment and include
in the javadoc :-)

Jacek

-- 
Jacek Laskowski
Notatnik Projektanta Java EE - http://jaceklaskowski.pl
Kapituła Javarsovia 2010 - http://javarsovia.pl

Reply via email to