多线程计数
public AllDataEntity getAllDdata() throws Exception{
AllDataEntity allDataEntity = new AllDataEntity();
int countThread = 8;
CountDownLatch latch = new CountDownLatch(countThread);
ExecutorService service = ThreadPoolUtil.getExecutor();
service.execute(new DATACreate(allDataEntity, planMgr, latch));
service.execute(new DATACreate(allDataEntity, collectMgr, latch));
service.execute(new DATACreate(allDataEntity, editMgr, latch));
service.execute(new DATACreate(allDataEntity, distributeMgr, latch));
service.execute(new DATACreate
service.execute(new DATACreate(allDataEntity, topReleaseMgr, latch));
service.execute(new DATACreate(allDataEntity, threeDistributeMgr, latch));
service.execute(new DATACreate(allDataEntity, centerMgr, latch));
latch.await();
return allDataEntity;
}
private class DATACreate implements Runnable{
AllDataEntity allDataEntity;
IJsonCreate iJsonCreate;
CountDownLatch latch;
public DATACreate(AllDataEntity allDataEntity, IJsonCreate iJsonCreate, CountDownLatch latch) {
this.allDataEntity = allDataEntity;
this.iJsonCreate = iJsonCreate;
this.latch = latch;
}
public void run() {
try {
T json = iJsonCreate.getJson();
Class<?> clazz = json.getClass();
Field[] fields = allDataEntity.getClass().getDeclaredFields();
for (Field each : fields) {
if(each.getType() == clazz) {
each.setAccessible(true);
each.set(allDataEntity, json);
}
}
} catch(Exception e) {
log.error("中央厨房获取数据异常: " + e.getMessage());
emailSendHelper.sendWarningEmail(“central_kitchen1_data”, "中央厨房获取数据异常 ", "中央厨房获取数据异常: " + e.getMessage(), receiver);
}
finally{
latch.countDown();
}
}
不定期更新~