多线程相关 Sucha
1、用多线程的方法查数据库
- 提示:此种方法依赖于俞雪华师父的自创jar包commons-lang.jar ,com.loserico.common.lang
- 使用封装好的多线程执行类
//早餐时间
BalanceReportDTO balanceReportMorning = new BalanceReportDTO();
//中餐时间
BalanceReportDTO balanceReportNoon = new BalanceReportDTO();
//晚餐时间
BalanceReportDTO balanceReportAfternoon = new BalanceReportDTO();
//多线程查早中晚人次
FutureResult<List<BalanceReportExt>> morningFuture = Concurrent.submit(() -> balanceReportDao.search(balanceReportMorning));
FutureResult<List<BalanceReportExt>> noonFuture = Concurrent.submit(() -> balanceReportDao.search(balanceReportNoon));
FutureResult<List<BalanceReportExt>> afternoonFuture = Concurrent.submit(() -> balanceReportDao.search(balanceReportAfternoon));
//等待所有线程完成
Concurrent.await();
List<BalanceReportExt> morningExts = morningFuture.get();
List<BalanceReportExt> noonExts = noonFuture.get();
List<BalanceReportExt> afternoonExts = afternoonFuture.get();