gpt4 book ai didi

Java 并发 : How can I tell which Future belongs to which Callable during processing?

转载 作者:搜寻专家 更新时间:2023-10-31 08:20:42 24 4
gpt4 key购买 nike

我有一个 Callable 集合和一个 ExecutorService。当我调用 All 时,我得到了一个 Future 对象的列表。在 Future 完成之前,我如何知道哪个 Future 对象映射到哪个 Callable?我可以事后说,因为

代码:

 ExecutorService es = .....;

Collection<Callables> uniqueCallables = .....; // each Callable is unique!

List<Future> futures = es.invokeAll(uniqueCallables);

// TODO--find unique Future A which is the future for Callable A!

最佳答案

基于 Java reference , invokeAll(uniqueCallables)保留 List<Future> 中的顺序作为 uniqueCallables.iterator() 产生的订单:

Returns: A list of Futures representing the tasks, in the same sequential order as produced by the iterator for the given task list, each of which has completed.

关于Java 并发 : How can I tell which Future belongs to which Callable during processing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10304843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com