jdk1.8异步:
//异步,无返回数据
CompletableFuture.runAsync(()-> {
logger.info("xxx-> xxx.");
// TODO
}).exceptionally(e->{
logger.error("###xxx->xxx failed:", e);
return null;
}).join();
CompletableFuture getTask=CompletableFuture.supplyAsync(()->{
return xxxService.getXXX(po.getId());
}).thenCombine(CompletableFuture.supplyAsync(()->{
return xxxxxxService.getXXXX(po.getId());
}),(first,second)->toVotes(first,second)).exceptionally(e->{
logger.error("",e);
return null;
});
list= (List<XxxPO>) getTask.get(RedisConst.REDIS_TIME_OUT, TimeUnit.SECOND);
private CompletableFuture<VO> getXXXId(long id){
CompletableFuture<VO> task=CompletableFuture.supplyAsync(()->{
VO vo=null;
try {
// TODO
return vo;
} catch (TException e) {
logger.error("xxx fail!",e);
}
return vo;
});
return task;
}
CompletableFuture<VO> task = this.getXXX(id);
infoList.add(task.get(TIME_OUT, TimeUnit.SECONDS));