I would like to use the constructor on the ExecutorCompletionService which takes a pre-defined BlockingQueue.
Can anyone provide a code snippet to show how this is done. It seems only to take a a BlockingQueue with Futures. How does this match with the fact that submit must be done with Callables.
I’m getting a little confused here – please help…
The
Callablessupplied tosubmit()will be wrapped up internally asFutureTasks, and it’s those (or a wrapper around one) that will eventually be inserted into the provided queue. That’s all an implementation detail, though. (And, note, that this use case of inserting the outcome into the queue is the main reason why there’s a protecteddone()method inFutureTask.) The contract says that result-yielding functions go in, and eventually results come out. TheFutures drawn from the queue represent the eventual outcomes of the functions you submitted earlier.