使用invokeAll方法获取Future对象时遇到以下错误。我正在尝试实现ExecutorService以并行调用。
错误〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉java.util.concurrent.执行异常:java.lang.不支持的操作异常
代码片段
主要类别:
ExecutorService exService = Executors.newFixedThreadPool(1);
List<CallableTask> listOfTask = new ArrayList<CallableTask>();
Map<String, String> param1= params;
param1.put("catCode", "XX278293##X");
listOfTask.add(new CallableTask(param1));
List<Future<Map<String,String>>> resultSet = exService.invokeAll(listOfTask);
for(Future<Map<String,String>> result : resultSet){
if(result.isDone()){
Map<String,String> response = result.get(); <<----------Facing Error in this line
}
}
exService.shutdown();
类可调用任务:
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.Callable;
class CallableTask implements Callable<Map<String, String>>{
private String name;
private Map<String, String> params;
public CallableTask(Map<String, String> params){
this.name=params.get("catCode");
this.params =params;
}
@Override
public Map<String, String> call() throws Exception {
boolean data = false;
//REST CALL
Map<String, String> resultData = Collections.emptyMap();
resultData.put("result", name+data);
//Getting response upto here
return resultData;
}
}
提前谢谢你!!!
1条答案
按热度按时间krugob8w1#
实际上,例外情况发生在这里:你不能调用
emptymap#put
:Future#get
只报告CallableTask
执行过程中发生的异常: