List<CompletableFuture<Response>> futures = new ArrayList<>();
List<Response> accountKeys = Lists.newArrayList();
for(int i = 1 ; i <= returnAccounts.size() ; i++){
final int idx = i;
CompletableFuture<Response> future = CompletableFuture.supplyAsync(() -> httpCall());
futures.add(future);
if(i % 20 == 0){
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
accountKeys.addAll(futures.stream().map(CompletableFuture::join).collect(Collectors.toList()));
futures = new ArrayList<>();
}
}
if(!futures.isEmpty()){
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
accountKeys.addAll(futures.stream().map(CompletableFuture::join).collect(Collectors.toList()));
}
System.out.println(accountKeys);
반응형
'꺼내먹어요' 카테고리의 다른 글
AWS Lambda Image Architecture - arm64, x86_64의 차이 (0) | 2025.02.20 |
---|---|
bash grep, cut, >(Redirection) 활용 (0) | 2023.01.31 |
Java List를 Map으로 변경 (0) | 2023.01.25 |
AWS SES Java SDK 여러명 Email 전송 로직 (0) | 2023.01.01 |
Collectors.groupingBy() - Java List 특정 기준으로 그룹 나누기 (0) | 2023.01.01 |