Loading

java future 并发简单实现

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(){
}
posted @ 2018-07-03 10:09  亡灵族  阅读(327)  评论(0编辑  收藏  举报