[concurrency-interest] Receiving notifications from Futures

Mark Thornton mthornton at optrak.co.uk
Mon May 18 08:59:19 EDT 2009


Manik Surtani wrote:
> Hi
>
> I'm creating an API that returns Futures.  One of the things that may 
> be useful to callers is to be notified when the Future completes, so 
> rather than doing a future.get(), the thread can register a callback 
> on the future and proceed with other stuff instead, being notified 
> when the future has completed and can then call future.get() to 
> retrieve any results.
When I thought I wanted notification I found it easier to change the API 
so that it adds completed results to a Collection (normally a threadsafe 
queue). Then if I still want notification I can provide a Collection 
implementation which notifies interested parties when it becomes non empty.

Mark Thornton



More information about the Concurrency-interest mailing list