public List<KpiVO> getHasValueKPI(KpiVO tableVo,String patientIdNumber) throws InterruptedException {
List<KpiVO> tempList = new ArrayList<>();
List<KpiVO> childrenList = patient360Dao.getKpiChildren(tableVo.getDesc(),tableVo.getName());
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5,10,0, TimeUnit.SECONDS,new ArrayBlockingQueue<Runnable>(30),new ThreadPoolExecutor.AbortPolicy());
final CountDownLatch latch = new CountDownLatch(childrenList.size());
for(KpiVO kpiVO : childrenList){
threadPoolExecutor.execute(() ->{
Integer total = patient360Dao.getTotal(patientIdNumber,kpiVO.getOrgCode(),kpiVO.getTableName(),kpiVO.getName());
if(total >0){
kpiVO.setTotal(total);
tempList.add(kpiVO);
}
//2、子线程执行完毕,计数减1
latch.countDown();
});
}
//3、主线程阻塞,等计数器==0,唤醒主线程往下执行。
latch.await();
threadPoolExecutor.shutdown();
return tempList;
}
java多线程处理业务,合并处理结果
最新推荐文章于 2023-11-10 17:30:09 发布