Executor executor = ...;
List<Callable<T>> tasks = List.of(...);
CompletionService<T> completionService = new ExecutorCompletionService<>(executor);
tasks.forEach(completionService::submit);
for (int i = 0; i < tasks.size(); i++) {
T result = completionService.take().get();
// A task has completed. Use its result.
}
1条答案
按热度按时间xoshrz7s1#
那是什么
ExecutorCompletionService
是给你的。