A service that decouples the production of new asynchronous tasks
from the consumption of the results of completed tasks. Producers
submit tasks for execution. Consumers take
completed tasks and process their results in the order they
complete. A CompletionService can for example be used to
manage asynchronous I/O, in which tasks that perform reads are
submitted in one part of a program or system, and then acted upon
in a different part of the program when the reads complete,
possibly in a different order than they were requested.
Typically, a CompletionService relies on a separate
Executor to actually execute the tasks, in which case the
CompletionService only manages an internal completion
queue. The ExecutorCompletionService class provides an
implementation of this approach.
API:
ExecutorCompletionService(Executor executor)
Creates an ExecutorCompletionService using the supplied
executor for base task execution and a
LinkedBlockingQueue as a completion queue.
ExecutorCompletionService(Executor executor,
BlockingQueue<Future> completionQueue)
Creates an ExecutorCompletionService using the supplied
executor for base task execution and the supplied queue as its
completion queue.
本文深入探讨了CompletionService的概念,一种将任务生产和消费分离的服务,允许在程序的不同部分提交和处理异步任务。通过使用Executor进行任务执行,CompletionService管理内部完成队列,特别适用于异步I/O操作。
9628

被折叠的 条评论
为什么被折叠?



