2021年1月20日星期三

Why does springboot take longer to execute than one child thread at a time?

  1. service @Async("taskExecutor") public CompletableFuture<List> getSiteClickTotal(String startTime, String endTime, Integer size){

        Instant now = Instant.now();      List<SiteCilckPojo> siteClickTotal = countPageInfoMapper.getSiteClickTotal(startTime, endTime, size);      Instant now1 = Instant.now();      long between = ChronoUnit.MILLIS.between(now, now1);      log.warn("current thread execution time -> {}  ,current thread -> {},params -> {} ,  {} , method -> {}",between,Thread.currentThread().getName(),startTime,endTime,"getSiteClickTotal");      return CompletableFuture.completedFuture(siteClickTotal);    }   
  2. Executing multiple threads at once @Override public Map<String, Object> getSiteClickOfDept() { Map<String, Object> objectObjectHashMap = Maps.newHashMap(); try {

          CompletableFuture<List<SiteCilckPojo>> siteClickTotalweek =                siteClickAsyncService.getSiteClickTotal(                        DateUtils.getFirstDayOfWeek(LocalDate.now()), DateUtils.getLastDayOfWeek(LocalDate.now())                        , 10);        CompletableFuture<List<SiteCilckPojo>> siteClickTotalmonth =           siteClickAsyncService.getSiteClickTotal(DateUtils.getfirstDayOfMonth(LocalDate.now()), DateUtils.getLastDayOfMonth(LocalDate.now()), 10);        CompletableFuture<List<SiteCilckPojo>> siteClickTotal =                siteClickAsyncService.getSiteClickTotal("", "", 10);        CompletableFuture<SiteCilckPojo> allTotal = siteClickAsyncService.getAllTotal("", "");          CompletableFuture<SiteCilckPojo> allTotalToday = siteClickAsyncService.getAllTotal(DateUtils.getFirstToday(LocalDate.now()),                DateUtils.getLastToday(LocalDate.now()));        CompletableFuture<SiteCilckPojo> allTotalYesterday = siteClickAsyncService.getAllTotal(DateUtils.getFirstYesterday(LocalDate.now()),                DateUtils.getLastYesterday(LocalDate.now()));        CompletableFuture<SiteCilckPojo> noTjTotal = siteClickAsyncService.getNoTjTotal("", "");        CompletableFuture<SiteCilckPojo> noTjTotalToday = siteClickAsyncService.getNoTjTotal(DateUtils.getFirstToday(LocalDate.now()),                DateUtils.getLastToday(LocalDate.now()));        CompletableFuture<SiteCilckPojo> noTjTotalYesterday = siteClickAsyncService.getNoTjTotal(DateUtils.getFirstYesterday(LocalDate.now()),                DateUtils.getLastYesterday(LocalDate.now()));        CompletableFuture.allOf(siteClickTotalweek, siteClickTotalmonth, siteClickTotal).join();         List<SiteCilckPojo> siteCilckPojos = siteClickTotalweek.get();        List<SiteCilckPojo> siteCilckPojos1 = siteClickTotalmonth.get();        List<SiteCilckPojo> siteCilckPojos2 = siteClickTotal.get();        SiteCilckPojo siteCilckPojo = allTotal.get();        SiteCilckPojo siteCilckPojo1 = allTotalToday.get();        SiteCilckPojo siteCilckPojo2 = allTotalYesterday.get();        SiteCilckPojo siteCilckPojo3 = noTjTotal.get();        SiteCilckPojo siteCilckPojo4 = noTjTotalToday.get();        SiteCilckPojo siteCilckPojo5 = noTjTotalYesterday.get();        CompletableFuture<List<Map<String, Object>>> dataOfDept = siteClickAsyncService.createDataOfDept(siteCilckPojos, siteCilckPojos1, siteCilckPojos2);        CompletableFuture<Map<String, Object>> data = siteClickAsyncService.createData(siteCilckPojo, siteCilckPojo1, siteCilckPojo2, siteCilckPojo3, siteCilckPojo4, siteCilckPojo5);        CompletableFuture.allOf(dataOfDept, data).join();        List<Map<String, Object>> maps = dataOfDept.get();        Map<String, Object> stringObjectMap = data.get();        objectObjectHashMap.put("deptTotal",maps);        objectObjectHashMap.put("total",stringObjectMap);    } catch (Exception e) {        e.printStackTrace();    }    return objectObjectHashMap;  

    }

https://stackoverflow.com/questions/65820228/why-does-springboot-take-longer-to-execute-than-one-child-thread-at-a-time January 21, 2021 at 10:04AM

没有评论:

发表评论