另一个场景就是API聚合的场景,需要并行调用多个接口,将结果进行组装。public Object aggregationApi() {
long s = System.currentTimeMillis();
List ids = new ArrayList<>();
ids.add(“1”);
ids.add(“2”);
ids.add(“3”);
Map<String, UserResponse> callResult = AsyncTemplate.call(ids, id -> {
return userService.getUser(id);
}, u -> u.getId(), COMMON_POOL);
long e = System.currentTimeMillis();
System.out.println(“耗时:” + (e-s) + “ms”);
return “”;
}
public
最新推荐文章于 2022-03-03 13:47:12 发布