[concurrency-interest] When do you use wait/notify?

Doug Lea dl@cs.oswego.edu
Sun, 25 Jan 2004 09:05:14 -0500


> In my case, I am unhappy with the cancel method as the future has no 
> idea which task is going to calculate its contents and most tasks 
> produce more than one Future, so killing them would stop other 
> (necessary) values from being calculated!

(We in the expert group considered this issue several times: Some
applications cannot live without cancellability, and some cannot live
with it. But it wouldn't work out at all well to define parallel APIs
differing only with respect to this. The compromise was to allow the
cancel method to return false if it cannot, or just doesn't want to
cancel the task. So, "return false" is a valid implementation.)

> I agree that I could easily create a class that implements the 
> java.util.concurrency.Future interface and has a no-parameter 
> constructor (and doesn't cancel anything). However, to do that would 
> involve using cals to wait() and notifyAll(). 

Right. That's a great example; thanks!  While we set up interfaces to
allow such variants in concrete Future classes, we don't, and can't,
provide all of the support that you might need to build all possible
custom implementations.


-Doug