生成二位码后导出到 execl 缓慢,大佬有什么解决方法
source link: https://www.v2ex.com/t/821904
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
lcq 8 小时 31 分钟前
//获取全部数据
ResultBody<List<CouponCodeExchangeListVO>> resultBody = couponCodeFeignClientService.getListByRuleId(map.get("ruleId").toString());
List<CouponCodeExchangeListVO> records = resultBody.getData();
List<CouponCodeExchangeListExcelVO> couponCodeExchangeListExcelVOS = new ArrayList<>();
List<Future<List<CouponCodeExchangeListExcelVO>>> futures = new ArrayList<>();
if (CollectionUtil.isNotEmpty(records)) {
int totalNum = records.size();
int batchNum;
if (totalNum <= 1000){
batchNum = 200;
}else {
batchNum = 500;
}
int pageNum = totalNum % batchNum == 0 ? totalNum / batchNum : totalNum / batchNum + 1;
List<CouponCodeExchangeListVO> subData;
int toIndex, fromIndex;
List<ExportCouponCodeTask> tasks = new ArrayList<>();
for (int i = 0; i < pageNum; i++) {
fromIndex = i * batchNum;
toIndex = Math.min(totalNum, fromIndex + batchNum);
subData = records.subList(fromIndex, toIndex);
tasks.add(new ExportCouponCodeTask(subData));
}
//分批使用多线程处理
if(!exportCouponCodeThreadPoolExecutor.isShutdown()){
futures = exportCouponCodeThreadPoolExecutor.invokeAll(tasks);
}
}
for (Future<List<CouponCodeExchangeListExcelVO>> future : futures) {
List<CouponCodeExchangeListExcelVO> couponCodeExchangeListExcelVOS1 = future.get();
couponCodeExchangeListExcelVOS.addAll(couponCodeExchangeListExcelVOS1);
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK