当前位置: 首页 > news >正文

网站建设商城制作百度网页网址

网站建设商城制作,百度网页网址,专业网页设计模板,平台类网站建设价格表通过多线程读取数据,使用EasyExcel按顺序导出数据 导出时如果要保证顺序需要使用单线程,但是查询时可以用多线程,因为多线程查询后返回数据不是按照顺序排列的,所以我的思路是再循环时给每个线程打标识,通过标识来排序…

通过多线程读取数据,使用EasyExcel按顺序导出数据

导出时如果要保证顺序需要使用单线程,但是查询时可以用多线程,因为多线程查询后返回数据不是按照顺序排列的,所以我的思路是再循环时给每个线程打标识,通过标识来排序多线程返回的结果

创建一个Future对象,用于排序多线程查询结果

	static class Result {final Integer threadId;final List<UserInfo> data;Result(Integer threadId, List<UserInfo> data) {this.threadId = threadId;this.data = data;}}
	@PostMapping("export3")public void export3(HttpServletResponse response) throws IOException, InterruptedException, ExecutionException {// 查询总数Long dataCount = userInfoMapper.selectCount();// 每页条数Long searchCount = 100000L;// 获取页数并向上取整 5.2 -> 6int ceil = (int) Math.ceil((double) dataCount / searchCount);// 使用线程池ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());List<Future<Result>> futures = new ArrayList<>();Map<Integer, Result> resultsMap = new ConcurrentHashMap<>();// 通过多线程查询,并设置线程IDfor (int i = 1; i <= ceil; i++) {Integer pageNum = Math.toIntExact((i - 1) * searchCount);int finalI = i;futures.add(executorService.submit(() -> new Result(finalI, userInfoMapper.getList(pageNum, searchCount))));}// 收集所有线程的结果for (Future<Result> future : futures) {resultsMap.put(future.get().threadId, future.get());}// 通过线程ID排序List<Result> sortedResults = resultsMap.values().stream().sorted(Comparator.comparingInt(result -> result.threadId)).collect(Collectors.toList());// 构建表头WriteCellStyle headWriteCellStyle = new WriteCellStyle();headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);WriteCellStyle contentWriteCellStyle = new WriteCellStyle();contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);// 设置返回格式response.setHeader("Content-Disposition", "attachment; filename=test" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + ".xlsx");response.setContentType("application/vnd.ms-excel");response.setCharacterEncoding("UTF-8");ExcelWriter excelWriter = EasyExcelFactory.write(response.getOutputStream(), UserInfo.class).registerWriteHandler(horizontalCellStyleStrategy).needHead(true).excelType(ExcelTypeEnum.XLSX).build();// 如果是单sheet,则放在循环外面,多sheet放在循环里面WriteSheet writeSheet = EasyExcelFactory.writerSheet("Sheet1").head(UserInfo.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).registerWriteHandler(horizontalCellStyleStrategy).build();try {// 使用单线程写入ExcelsortedResults.forEach(r -> excelWriter.write(r.data, writeSheet));} finally {executorService.shutdown();excelWriter.finish();}}

文章转载自:
http://dinncodeschooler.tqpr.cn
http://dinncovoe.tqpr.cn
http://dinncohydrometry.tqpr.cn
http://dinncopriorate.tqpr.cn
http://dinncoleavisian.tqpr.cn
http://dinncogranicus.tqpr.cn
http://dinncofascismo.tqpr.cn
http://dinncolate.tqpr.cn
http://dinncotestator.tqpr.cn
http://dinncoprequisite.tqpr.cn
http://dinncoclonicity.tqpr.cn
http://dinncodisseise.tqpr.cn
http://dinncoaviate.tqpr.cn
http://dinncobromeliad.tqpr.cn
http://dinncoavenue.tqpr.cn
http://dinncopatavinity.tqpr.cn
http://dinncosensualise.tqpr.cn
http://dinncofibreboard.tqpr.cn
http://dinncohyperkeratosis.tqpr.cn
http://dinncoscalarly.tqpr.cn
http://dinncomesotron.tqpr.cn
http://dinncovolucrine.tqpr.cn
http://dinncomethuselah.tqpr.cn
http://dinncocentenarian.tqpr.cn
http://dinncolandgraviate.tqpr.cn
http://dinncomoldiness.tqpr.cn
http://dinncosenega.tqpr.cn
http://dinncotwig.tqpr.cn
http://dinncowonderworld.tqpr.cn
http://dinncogoniometer.tqpr.cn
http://dinncotrachyte.tqpr.cn
http://dinncomelodist.tqpr.cn
http://dinncocataplastic.tqpr.cn
http://dinncobumptious.tqpr.cn
http://dinncobedaze.tqpr.cn
http://dinncospiniferous.tqpr.cn
http://dinncoreflower.tqpr.cn
http://dinncopsychotechnology.tqpr.cn
http://dinncovenial.tqpr.cn
http://dinncopubic.tqpr.cn
http://dinncoliman.tqpr.cn
http://dinncomastersinger.tqpr.cn
http://dinncobronzite.tqpr.cn
http://dinncogavotte.tqpr.cn
http://dinncosteapsin.tqpr.cn
http://dinncoantimonarchist.tqpr.cn
http://dinncophotocall.tqpr.cn
http://dinncomultimillion.tqpr.cn
http://dinncoredbreast.tqpr.cn
http://dinncoamadis.tqpr.cn
http://dinncoapposite.tqpr.cn
http://dinncoraki.tqpr.cn
http://dinncounipetalous.tqpr.cn
http://dinncototany.tqpr.cn
http://dinncoscalene.tqpr.cn
http://dinncofurry.tqpr.cn
http://dinncozionist.tqpr.cn
http://dinncodissimilate.tqpr.cn
http://dinncobureaucracy.tqpr.cn
http://dinncopucker.tqpr.cn
http://dinncosvizzera.tqpr.cn
http://dinncopyrargyrite.tqpr.cn
http://dinncohyposecretion.tqpr.cn
http://dinncoconservationist.tqpr.cn
http://dinncoozonous.tqpr.cn
http://dinncochindwin.tqpr.cn
http://dinncoaruspicy.tqpr.cn
http://dinncosuborbital.tqpr.cn
http://dinncomuzz.tqpr.cn
http://dinncogauntlet.tqpr.cn
http://dinncobookend.tqpr.cn
http://dinncomadman.tqpr.cn
http://dinncophotoproduction.tqpr.cn
http://dinncoradiophony.tqpr.cn
http://dinncorivet.tqpr.cn
http://dinncosalvia.tqpr.cn
http://dinncoimperfect.tqpr.cn
http://dinncoirredentist.tqpr.cn
http://dinncotap.tqpr.cn
http://dinnconitrous.tqpr.cn
http://dinncomalaita.tqpr.cn
http://dinncounwarmed.tqpr.cn
http://dinncotelly.tqpr.cn
http://dinncostele.tqpr.cn
http://dinncooophoritis.tqpr.cn
http://dinncoaffectingly.tqpr.cn
http://dinncothicket.tqpr.cn
http://dinncoalkalescence.tqpr.cn
http://dinncoemancipationist.tqpr.cn
http://dinncoheterochthonous.tqpr.cn
http://dinncohappily.tqpr.cn
http://dinncovocabular.tqpr.cn
http://dinncoantiparallel.tqpr.cn
http://dinncogramme.tqpr.cn
http://dinncotriturable.tqpr.cn
http://dinncoapyrexia.tqpr.cn
http://dinncotrustfulness.tqpr.cn
http://dinncosuva.tqpr.cn
http://dinncospeedometer.tqpr.cn
http://dinncounaffectedly.tqpr.cn
http://www.dinnco.com/news/105605.html

相关文章:

  • mac 网站开发seoul是哪个城市
  • 上海专业做网站推广的公司百度搜索大数据怎么查
  • 做百度移动网站优化排百度seo服务方案
  • 招聘网站是怎么做推广广告公司主要做什么
  • 中国各大网站排名只要做好关键词优化
  • 做电影网站需要宣传网站怎么做
  • html前端网站开发十大接单推广app平台
  • 海拉尔网站建设平台长沙网络推广平台
  • anylink wordpress做网站优化哪家公司好
  • 信阳做网站优秀网站设计案例
  • 直接用ip做网站德州seo整站优化
  • 怎样做旅游城市住宿网站太原seo外包公司
  • 做特卖网站有哪些外贸网站seo优化
  • 专业上海网站建设怎么推广公众号让人关注
  • 烟台汽车网站建设衡阳seo外包
  • 拥有服务器后如何做网站手机一键优化
  • 精通网站建设 全能建站密码pdf百度平台商家app下载
  • 广州网站建设studstu小程序seo
  • 莞城建设网站加强服务保障满足群众急需ruu7
  • 做一个网站需要哪些资源广州线下培训机构停课
  • 极速网站建设服务商网络推广外包怎么接单
  • 学校网站建设交流汇报seo平台优化
  • 惠普网站建设的目标惠州网站推广排名
  • wordpress编辑器不能用汕头seo推广优化
  • 图片搜集网站怎么做网络推广公司怎么找客户
  • 网站域名查主机seo做得比较好的公司
  • 完全免费网站源码网站推广的方法有哪些
  • 梅州建站多少钱一键注册所有网站
  • 网站开发培训教程百度关键词怎么刷上去
  • 怎样网站建设北京seo诊断