[concurrency-interest] Receiving notifications from Futures

Sam Berlin sberlin at gmail.com
Mon May 18 10:40:47 EDT 2009

We needed this also, so came up with a "ListeningFuture" and surrounding API
(that also utilizes a separate listening package we've come up with, but
it's easy to divorce it from the listening package if necessary).


& the classes:
 ListeningFuture [the interface that adds listening]
 ListeningFutureExecutorService [extension to ExecutorService that returns
ListeningFutures instead of Futures]
 ListeningFutureTask [an implementation of FutureTask that sends events]
 RunnableListeningFuture [an extension to RunnableFuture that adds
 RunnableScheduledListeningFuture [an extension to RunnableScheduledFuture
that adds listening]
 ScheduledListeningFuture [an extension to ScheduledFuture]
 ScheduledListeningExecutorService [an extension to ScheduledExecutorService
that returns ScheduledListeningFutures]
 ThreadPoolListeningExecutor [an extension to ThreadPoolExecutor]
 AbstractListeningExecutorService [an extension to AbstractExecutorService]
 FutureEvent [the event a listening future sends]


On Mon, May 18, 2009 at 8:38 AM, Manik Surtani <manik at jboss.org> 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.
> I have looked at the CompletionService API, and while this does help to
> some degree, it is still not something I can expose to any calling code,
> mainly because calling code does not register Callables on my interface.
>  Instead it calls methods that return Futures.
> I'm guessing I cannot be the first person with the need for a notifying
> future - how has this been achieved before?
> I was thinking of something like:
> public interface  NotifyingFuture<T> extends Future<T> {
>   NotifyingFuture<T> notifyOnCompletion(NotifyingListener<T> l);
>  }
> public interface NotifyingListener<T> {
>  void futureCompleted(NotifyingFuture<T> f);
> }
> so that calling code could do:
> Future f =
> myAPI.masyncMethodThatReturnsFuture().notifyOnCompletion(listener);
> Cheers
> Manik
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20090518/40c32aa4/attachment.html>

More information about the Concurrency-interest mailing list