1

生成二位码后导出到 execl 缓慢,大佬有什么解决方法

 2 years ago
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.
neoserver,ios ssh client

V2EX  ›  Java

生成二位码后导出到 execl 缓慢,大佬有什么解决方法

  lcq · 8 小时 32 分钟前 · 205 次点击
1.表里有 1W 条数据2.循环给里面的链接生成二维码3.导出到 execl注:已使用多线程跑,但还是很缓慢,接口响应直接到了 50s

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);
}


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK