[concurrency-interest] Why does FutureTask hold reference to the Callable object forever?

Tim Peierls tim at peierls.net
Thu Jan 24 11:21:12 EST 2008


On Jan 24, 2008 5:18 AM, Endre Stølsvik <Online at stolsvik.com> wrote:

> Check decorateTask(...): please enlighten me on exactly HOW you're
> supposed to use those methods to really decorate your task, while still
> honoring the contract under which the Runnable/Callable was enqueued.
>

"Task" in decorateTask (and in AbstractExecutorService.newTaskFor) refers to
the Runnable(Scheduled)Future, not to the submitted Runnable/Callable. These
methods probably should have been named "decorateFuture" and "newFutureFor".


The point of these methods is to give subclasses a chance to supply a
different concrete type for the Runnable(Scheduled)Future returned when a
Runnable/Callable is submitted. Without these methods, there's no way to do
this that doesn't involve a huge amount of reimplementation of existing
code.

I added an example to the wiki of using decorateTask to provide cancellation
behavior in a custom scheduled executor service:

http://artisans-serverintellect-com.si-eioswww6.com/default.asp?W30

--tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20080124/c8bf7125/attachment.html 


More information about the Concurrency-interest mailing list