Map<String, Future<String[]>> futures = new LinkedHashMap<String, Future<String[]>>();
futures.put(Line_Num, executorService.submit(api));
for (Map.Entry<String, Future<String[]>> entry : futures.entrySet()) {
String futuresKey = entry.getKey();
Future<String[]> futuresValue = entry.getValue();
try {
String[] resStr = futuresValue.get();
if (null != resStr) {
String strKey = resStr[0];
String strResult = resStr[1];
}
}
}
本文介绍了一种使用Map和Future进行异步任务处理的方法,通过将任务提交到线程池并存储Future对象,实现了对多个异步操作的统一管理和结果的有序获取。
2391

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



