是不是这样使用的呢?谢谢!
/** * 异步发送 * * @param id */ @Async("taskExecutor") public void sendAgencyMessage(String id) { log.info("异步通知"); // 参数传递用id,使用更小的字节放入缓存队列 messageJobService.sendAgencyMessage(null,id); }
另一种用法:
@Autowired private TaskExecutor taskExecutor; public ResultVO findHandlingRecordByAssociationId(Integer associationId) throws InterruptedException{ Map<String, Object> map = new HashMap<>(2); //线程计数器(等待所有线程执行完统一返回) CountDownLatch countDownLatch = new CountDownLatch(10); taskExecutor.execute(() -> { try { //service调用 map.put("HandlingRecord", legalLitigationService.findHandlingRecordByAssociationId(associationId)); }finally { countDownLatch.countDown(); } }); taskExecutor.execute(() -> { try { map.put("CaseBasic", legalLitigationService.findCaseDetailsById(associationId)); }finally { countDownLatch.countDown(); } }); countDownLatch.await(); return ResultVO.putSuccess(map); }
扫一扫访问 Blade技术社区 移动端