获取期货 Java 中的 ID
我有以下代码:
for (int i = 0; i < nComp; i++) {
Callable<Long> worker = new WSCaller(compConns[i]);
col.add(worker);
}
List<Future<Long>> results=null;
results = executor.invokeAll(col, timeout, TimeUnit.SECONDS);
for (Future<Long> future : results) {
if ( !future.isDone() ) {
// here I need to know which future timed-out ...
}
}
正如代码中所指出的...我怎样才能知道哪个 Future 超时了?
谢谢
I have the following code:
for (int i = 0; i < nComp; i++) {
Callable<Long> worker = new WSCaller(compConns[i]);
col.add(worker);
}
List<Future<Long>> results=null;
results = executor.invokeAll(col, timeout, TimeUnit.SECONDS);
for (Future<Long> future : results) {
if ( !future.isDone() ) {
// here I need to know which future timed-out ...
}
}
As pointed out in the code ... How can I know which Future timed-out ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅解决方案此处
你必须实现自己的计数器才能知道你的索引是什么。
see the solution here
you have to implement your own counter to know what index your are up to.
futures 按照与提交的 callables 相同的顺序返回,因此 callables 列表和 futures 列表中的索引之间存在一一对应的关系。
您可以使用传统的 for 循环,
或维护索引,
The futures are returned in the same order as the submitted callables, so there is a one to one correspondence between the indices in the callables list and futures list.
You can either use a traditional for loop,
or maintain an index,