时间:2021-07-01 10:21:17 帮助过:5人阅读
public List<Map> getCiServiceBadEvaNumStatistic(SAASIndexQuery saasIndexQuery) throws InvocationTargetException, IllegalAccessException { String startDate = saasIndexQuery.getStartDate(); String endDate = saasIndexQuery.getEndDate(); int days = DateUtil.getDatebetweenOfDayNum(DateUtil.parseDate(startDate,DateUtil.dateFormatPattern),DateUtil.parseDate(endDate,DateUtil.dateFormatPattern)); CompletionService<List<CiOrderStatisticSection>> completionService = new ExecutorCompletionService<List<CiOrderStatisticSection>>(executorService); List<CiOrderStatisticSection> allList = new ArrayList<>(); long start = System.currentTimeMillis(); logger.info("测试异步时间start:" + System.currentTimeMillis()); //CountDownLatch countDownLatch = new CountDownLatch(days); SAASIndexQuery everyDaySaas = new SAASIndexQuery(); BeanUtils.copyProperties(everyDaySaas,saasIndexQuery); for(int i = 0;i<days;i++){ everyDaySaas.setStartDate(DateUtil.afterNDay(saasIndexQuery.getStartDate(),i,DateUtil.dateFormatPattern)); everyDaySaas.setEndDate(DateUtil.afterNDay(everyDaySaas.getStartDate(),1,DateUtil.dateFormatPattern)); //countDownLatch.countDown(); int finalI = i; completionService.submit(new Callable<List<CiOrderStatisticSection>>() { @Override public List<CiOrderStatisticSection> call() throws Exception { //allList.addAll(biSaasCiDeviceDayExMapper.getCiServiceNegativeRate(saasIndexQuery)); //countDownLatch.countDown(); System.out.println("====="+ finalI +"====="); return biSaasCiDeviceDayExMapper.getCiServiceNegativeRate(saasIndexQuery); } }); } System.out.println("==============" + (System.currentTimeMillis()-start) + "毫秒"); long t = System.currentTimeMillis(); for (int i = 0;i<days;i++){ System.out.println("for循环耗时==============+"+i + (System.currentTimeMillis()-t) + "毫秒"); try { Future<List<CiOrderStatisticSection>> future = completionService.take(); List<CiOrderStatisticSection> ciList = future.get(); allList.addAll(ciList); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } long end = System.currentTimeMillis(); logger.info("测试异步时间end:" + (end-start) + "毫秒"); System.out.println("测试异步时间end:" + (end-start) + "毫秒"); }
测试后发现不对,使用多线程的take方式 每次都会有阻塞,这个阻塞一直没明白是哪里阻塞了? 是线程池、LinkedBlockingDeque 还是for循环 take时候 阻塞了 一直没明白,观察的结果就是每次for循环都要差不多200多毫秒,30个循环要6s多。。。。额,算了 ,还没有原来快呢
2.昨天换了种思路:直接从数据库查询时候做好控制。每次查询先根据月份和年份,查询出来id的最大值和最小值,之后sql里面查询时候加上id在这个最大值和最小是区间内。大概思路是这样:嗯,结果竟然可以。
sql优化:数据量过大查询优化
标签:form 场景 lin public util vat art ons nts