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

Endre Stølsvik Online at stolsvik.com
Thu Jan 24 05:18:49 EST 2008


Kwok, Grace (MSCIBARRA) wrote:
> Hi,
>  
>  
>       After a FutureTask is run and result is set to a local variable 
> internally inside FutureTask, I would think that the Callable object 
> should not be needed anymore.   I would think that it would be best the 
> reference to the Callable object be set to null.

Good point.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213323

FutureTask was/is bugridden in several ways: check out the 
implementation of run() vs. setException() and that "inner"-stuff (which 
feels like being coded in an obtuse way "just because"). Hint: when will 
"outer".setException ever be invoked?

Oops, now you got me started on ScheduledThreadPoolExecutor.. First of 
all, not having a proper cron-style schedule makes it next to worthless, 
IMO. Furthermore, it feels to me like it was hacked up without much testing:
   You'd expect its extension point afterExecute(Runnable r, Throwable 
t) to give you any throwables the task raised, right? But no, it doesn't 
(and the javadoc now also tries somewhat awkwardly to explain this 
rather fine point) - the extension of FutureTask (ScheduledFutureTask) 
swallows the Exception, although it is a non-static private internal 
class to STPE, and hence perfectly well could have been hooked.
   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. 
Hint: where's the parameters under which the job was enqueued? Even 
proxying/wrapping magic seems impossible: the STPE internal NONO_ORIGIN 
and now() is private, as is the class mentioned (Do note that I might 
just have missed the obvious - so don't take my word for it).

Although I love the work of these guys, I find this particular bunch of 
classes and interfaces to be rather unreasonable.

If you're into self-inflicted pain, here's the "dialogues" about these 
issues in Sun's bugbase:
   http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6459119
   http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6464365

Endre.


More information about the Concurrency-interest mailing list