void

jdk1.8异步

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));




posted on 2016-08-18 10:52 void 阅读(400) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: