开发者

How to use an ExecutorCompletionService

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 ge开发者_JAVA百科tting a little confused here - please help...


The Callables supplied to submit() will be wrapped up internally as FutureTasks, 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 protected done() method in FutureTask.) The contract says that result-yielding functions go in, and eventually results come out. The Futures drawn from the queue represent the eventual outcomes of the functions you submitted earlier.


The javadoc for ExecutorCompletionService has a large code sample in it, and the documented constructor takes a BlockingQueue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜