java 多线程等待返回结果,类比C#的Task
@Repository
public class XXXXService {
@Autowired
private ThreadPoolTaskExecutor tranExecutor;
public RequestResult BigSrceen() {
BigScreenDTO bigscreendto = new BigScreenDTO();
final CountDownLatch latch = new CountDownLatch(8);
tranExecutor.execute(() -> {
// 任务1
bigscreendto.setDevicestatistic(StatisticByDevice(orgnum));
latch.countDown();
});
tranExecutor.execute(() -> {
// 任务2
warnbymon.put("lastmonth", WarnByMon(lastyearstatisticdto));
bigscreendto.setWarnbymon(warnbymon);
latch.countDown();
})
try {
latch.await();
} finally {
return new RequestResult(bigscreendto);
}
}