//综合接口
@RequestMapping("/allOther")
public R allOther() throws Exception {
long start = System.currentTimeMillis();
//
ExecutorService threadPool = Executors.newFixedThreadPool(5);
List<Future<Object>> allOtherVO = new ArrayList<Future<Object>>();
//创建线程1,执行
Future<Object> result1 = threadPool.submit(new Callable<Object>() {
@Override
public List<ProvinceCountVO> call() throws Exception {
log.info("thread1 开始");
//30工单
List<ProvinceCountVO> provinceCountVOList = sdkStatisticsLogService.provinceCountBetweenDay();
log.info("thread1 结束");
return provinceCountVOList;
}
});
allOtherVO.add(result1);
//创建线程2,执行
Future<Object> result2 = threadPool.submit(new Callable<Object>() {
@Override
public List<TotalNumberOfInstalledXYVO> call() throws Exception {
log.info("thread2 开始");
//设备安装数
List<TotalNumberOfInstalledXYVO> totalNumberOfInstalled = appDeviceInstallService.totalNumberOfInstalled();
log.info("thread2 结束");
return totalNumberOfInstalled;
}
});
allOtherVO.add(result2);
//创建线程3,执行
Future<Object> result3 = threadPool.submit(new Callable<Object>() {
@Override
public List<FunctionalComparisonXYVO> call() throws Exception {
log.info("thread3 开始");
//设备安装对比
List<FunctionalComparisonXYVO> functionalComparisonVO = appPageVisitedService.functionalComparison();
log.info("thread3 结束");
return functionalComparisonVO;
}
});
allOtherVO.add(result3);
//创建线程4,执行
Future<Object> result4 = threadPool.submit(new Callable<Object>() {
@Override
public List<TheMapStatisticalVO> call() throws Exception {
log.info("thread4 开始");
//地图
List<TheMapStatisticalVO> theMapStatistical = statisticsLogTodayCountService.theMapStatistical();
log.info("thread4 结束");
return theMapStatistical;
}
});
allOtherVO.add(result4);
//创建线程5,执行
Future<Object> result5 = threadPool.submit(new Callable<Object>() {
@Override
public List<PvAndUvListVO> call() throws Exception {
log.info("thread5 开始");
//pv uv
List<PvAndUvListVO> pvAndUvListVOList = appPageVisitedService.pvAnduvList();
log.info("thread5 结束");
return pvAndUvListVOList;
}
});
allOtherVO.add(result5);
AllOtherVO allOtherVONew = new AllOtherVO();
for(int i=0;i<=4;i++){
Future future = allOtherVO.get(i);
while(true) {
if (future.isDone()) {
if (i == 0) {
allOtherVONew.setProvinceCountVOList((List<ProvinceCountVO>) future.get());
break;
}
if (i == 1) {
allOtherVONew.setTotalNumberOfInstalledVO((List<TotalNumberOfInstalledXYVO>) future.get());
break;
}
if (i == 2) {
allOtherVONew.setFunctionalComparisonVO((List<FunctionalComparisonXYVO>) future.get());
break;
}
if (i == 3) {
allOtherVONew.setTheMapStatisticalVOList((List<TheMapStatisticalVO>) future.get());
break;
}
if (i == 4) {
allOtherVONew.setPvAndUvListVOList((List<PvAndUvListVO>) future.get());
break;
}
}
}
}
//访问接口
long end = System.currentTimeMillis();
log.info("耗时:" + (end - start) + "ms");
log.info("线程执行成功");
return R.ok().data("token", "success").data("data", allOtherVONew);
}
Future内类型使用 Object 类型是因为我需要最后的返回数据是一个自定义结合类,根据你定义的去写就好