@Service
public class TestService{
@Resource
private AsyncService asyncService;
public void test(List<String> strs){
List<CompletableFuture> futures = new ArrayList<>();
for (String str: strs) {
CompletableFuture<Integer> integerFuture = asyncService.test(str);
futures.add(integerFuture);
}
CompletableFuture.allOf(ArrayUtil.toArray(futures, CompletableFuture.class)).join();
}
}
@Service
public class AsyncService{
@Async("asyncTask")
public CompletableFuture<Integer> test(String str) {
return CompletableFuture.completedFuture(1);
}
}