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

Tim Peierls tim at peierls.net
Thu Jan 24 22:50:04 EST 2008


On Jan 24, 2008 6:25 PM, Endre Stølsvik <Online at stolsvik.com> wrote:

> ... you _have to_ make a wrapper that forwards all calls, as you cannot
> yourself implement the actual needed behavior of the
> RunnableScheduledFuture, since STPE's implementation of it,
> ScheduledFutureTask, relies on the innards of STPE itself


It's true, you do have to make a forwarding wrapper. I put one on the wiki
just now, but it would be nice to have something like this in the standard
library:

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



> (and since you aren't supplied with the arguments of the initial submit).
>

Not sure how being supplied with those arguments would help you avoid the
need for a forwarding wrapper.


I tried using this feature (the decorateTask-methods) to implement
> Exception-catching by wrapping and overriding run(), but didn't manage to do
> it in any way (it hits me now that you could possibly proxy it and use the
> reflection stuff to change visibility of some of those private methods to
> make it possible to invoke them?).
>
> But such amazing wizardry is not what those methods are meant to enable
> you to do, then?


No.

If you want to wrap submitted Runnables, why not wrap them *before*
submission? If you want to encapsulate that behavior in a
ScheduledExecutorService, you could write a
RunnableWrappingScheduledExecutorService that forwards to an underlying
STPE, but wraps any submitted Runnables using a protected method,
wrap(Runnable) that by default just returns the Runnable itself.




> Maybe put some @Overrides in that example code?


Oops, thanks, just did.

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


More information about the Concurrency-interest mailing list