java future 并发简单实现

时间:2022-06-07 05:53:16
List<Future<>> futures = new ArrayList<>();
List<T> t= new ArrayList<>();
try {
List<> tmp= new ArrayList<....>
for (int i = 0; i < tmp.size(); i++){
futures.add(excutefunc());
}
}catch (Exception e){
logger.error("Error" + e.getMessage());
}
for(Future<CMCBuild> future : futures) {
try {
while (true) {
if (future.isDone() && !future.isCancelled()) {
T response1 = future.get();
t.add(response1);
break;
} else {
Thread.sleep(10);
}
}
} catch (Exception e) {
e.printStackTrace();
}
} @Async
excutefunc(){
}