Question

Is it safe to assume that

java.util.concurrent.CompletionService.take().isDone() 

will always return true? If so, why does take() return a Future, rather than the value directly? If not, what does "completed task" as used in the documentation mean?

Was it helpful?

Solution

Because you can use the Future for other things. You are given the future when you submit(). So you can first of all use the Future object returned to monitor the status or cancel prematurely. Second, if you change the futureFactory() (I think it is called something different but I have Java 5 not 6 installed) you can add all kinds of extra members to the future object.

So when doing the take(), you are right that in this case part of the future (the tracking/cancellation of state) isn't very useful. But OTOH, why not return the whole future as is, including extended functionality?

OTHER TIPS

That's what the javadoc seems to imply, take() blocks until it can return a finished Future which of course will be done when it's returned.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top