@Override public HomePagePopupResp getPopupData(HomePagePopupReq req) throws BusinessException { HomePagePopupResp homePagePopupResp = new HomePagePopupResp(); RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); try { // 创建线程池 ThreadPoolExecutor threadPool = new ThreadPoolExecutor(3, 20, 0, TimeUnit.SECONDS, new LinkedBlockingDeque<>(1024)); // 添加任务 threadPool.submit(new Runnable() { @Override public void run() { // /api/project-m-sit01/srv/intelFive/queryNoFinishMeetTenDay 通过用户ID查询距离回收日期10天内的已电约完成且未面见完成的客户(每天进入app首页弹出一次) List<NoFinishThreeDayResp> queryNoFinishMeetTenDayList = intelFiveService.queryNoFinishMeetTenDay(req.getMeetNoFinishTenDayReq()); if (CollectionUtil.isNotEmpty(queryNoFinishMeetTenDayList)){ homePagePopupResp.setQueryNoFinishMeetTenDayList(queryNoFinishMeetTenDayList); } log.info(String.format("/outer/homePage/popup >>>>任务QueryNoFinishMeetTenDayList执行完成")); } }); threadPool.submit(new Runnable() { @Override public void run() { // /api/project-m-sit01/srv/intelFive/queryNoFinishThreeDay 通过用户ID查询距离回收日期3天内的未完成电约的客户(每天进入app首页弹出一次) List<NoFinishThreeDayResp> noFinishThreeDayRespList = intelFiveService.queryNoFinishThreeDay(req.getUserCustRecordReq()); if (CollectionUtil.isNotEmpty(noFinishThreeDayRespList)){ homePagePopupResp.setNoFinishThreeDayRespList(noFinishThreeDayRespList); } log.info(String.format("/outer/homePage/popup >>>>任务NoFinishThreeDayRespList执行完成")); } }); threadPool.submit(new Runnable() { @Override public void run() { ///api/assess-sit01/srv/assess/poster/popupPoster 弹出海报,登录APP时调用 Map listR = assessRemoteService.doPopupPoster(req.getPosterReq()); if (ObjectUtil.isNotNull(listR)){ homePagePopupResp.setPosterRespList(listR); } log.info(String.format("/outer/homePage/popup >>>>任务PosterRespList执行完成")); } }); threadPool.shutdown(); }catch (Exception e){ throw new BusinessException("/outer/homePage/popup 调用失败"); } // ///api/project-m-sit01/srv/smart5/queryNewsCount?isChange=1 查询未接来电弹框状态 // AppelManqueClickResp appelManqueClickResp = appelManqueService.queryNewsCount(req.getIsChange()); // homePagePopupResp.setAppelManqueClickResp(appelManqueClickResp); return homePagePopupResp; } 该段代码 子线程如何获取请求头参数
时间: 2024-03-13 11:45:00 浏览: 52
子线程可以通过ThreadLocal来获取请求头参数。在主线程中,可以将请求头参数存储在ThreadLocal中,子线程可以通过ThreadLocal获取存储的请求头参数。具体实现可以参考以下代码:
```
// 在主线程中存储请求头参数到ThreadLocal中
ThreadLocal<Map<String, String>> threadLocal = new ThreadLocal<>();
threadLocal.set(requestAttributes.getAttribute("headerParams", RequestAttributes.SCOPE_REQUEST));
// 在子线程中获取请求头参数
threadPool.submit(new Runnable() {
@Override
public void run() {
// 从ThreadLocal中获取请求头参数
Map<String, String> headerParams = threadLocal.get();
// 子线程中的代码
}
});
```
阅读全文