1.因有个需求, 此需求是需要单查数据才可以查询准确的数据,但是前台参数是 按月份查询,所以需要查询月区间的每天的数据
2.使用countdownlatch
3.使用 private static ExecutorService executorService = Executors.newFixedThreadPool(5);
4.举例 8.1 - 9.30号,查看区间有多少天, 分割成5份,最后一份加上余数
6.每个线程中查询的对象,不可通用
7.举例
//例子
BigDecimal sta = new BigDecimal(start.getTime());
executorService.execute(new Runnable() {
@Override
public void run() {
for(int i = 0 ;i < every;i++){
BigDecimal sta2 = new BigDecimal(0);
sta2 = sta.add(new BigDecimal(i * 24 *60 *60 *1000));
start.setTime(sta2.longValue());
bomberDistributionFroms.setDayTime(DateUtilsSync.formatYMD(start));
List<Map<String, Object>> bomberDistributionReportForm = applicationMapper.getBomberCollectionReceiptStock(bomberDistributionFroms);
bomberDistributionReportFormResult.addAll(bomberDistributionReportForm);
}
countDownLatch.countDown();
}
});
//对照
BomberDistributionFroms finalBomberDistributionFroms = bomberDistributionFroms2;
BigDecimal sta8 = new BigDecimal(start2.getTime());
executorService.execute(new Runnable() {
@Override
public void run() {
BigDecimal sta2 = new BigDecimal(0);
sta2 = sta8.add(new BigDecimal(i * 24 *60 *60 *1000));
start2.setTime(sta2.longValue());
finalBomberDistributionFroms.setDayTime(DateUtilsSync.formatYMD(start2));
List<Map<String, Object>> bomberDistributionReportForm = applicationMapper.getBomberCollectionReceiptStock(finalBomberDistributionFroms);
bomberDistributionReportFormResult.addAll(bomberDistributionReportForm);
}
countDownLatch.countDown();
}
});
//最后 主线程等待
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
添加数据的list需要用 sync的list