java好好学习一天天向上

导航

 
for (TemplateSourceConfig templateSourceConfig : templateSourceConfigList) {
completableFutures.add(CompletableFuture.supplyAsync(() -> {
try {
Map<String, Object> paramMap = JsonUtil.javaBean2SnakeMap(reportUrlVO);
String url = templateSourceConfig.getSourceDomain() + templateSourceConfig.getSourceUrl();
String result = HttpUtil.get(url, paramMap);
processHttpResult(result, templateSourceConfig, errorJson, dataJsonList);
} catch (Exception e) {
log.error("调用第三方接口执行方法出错", e);
}
return null;
}, threadPoolExecutor));
}
try {
//等待线程池里面的线程执行完毕
CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])).get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.error("调用第三方接口InterruptedException出错", e);
throw new BusinessException(StatusCode.THREAD_EXCEPTION);
} catch (ExecutionException e) {
log.error("调用第三方接口ExecutionException出错", e);
throw new BusinessException(StatusCode.THREAD_EXCEPTION);
}
posted on 2022-06-07 16:01  好好学习一天天向上  阅读(58)  评论(0)    收藏  举报