@Autowired private ExecutorService executorService;
Set> callables = new HashSet>();
callables.add(new Callable() {
public Map call() throws Exception {
Map map = new HashMap();
return map;
}
});
callables.add(new Callable() {
public Map call() throws Exception {
Map map = new HashMap();
return map;
}
});
callables.add(new Callable() {
public Map call() throws Exception {
Map map = new HashMap();
return map;
}
});
callables.add(new Callable() {
public Map call() throws Exception {
Map map = new HashMap();
return map;
}
});
callables.add(new Callable() {
public Map call() throws Exception {
Map map = new HashMap();
return map;
}
});
List> futures = executorService.invokeAll(callables);// 收集线程返回的值
for(Future future : futures) {
Map map = future.get();// 各个线程返回的map集合
}