EDIT: I'm using java 8 so can't use executor to add delay.
I have to call an API multiple times to get a set of data. I do it using CompletableFuture as given below.Here I'm actually calling the method that calls the said API (getStockConversionResponse).
List<CompletableFuture<Void>> completableFutureList = hbbConnectionDetail.stream().map(connectionDetail -> CompletableFuture.supplyAsync(() -> getStockConversionResponse(connectionDetail, finalTeamLead, finalReceivePmsId), configuration.stockConversionExecutor()).thenAccept(stockDetailsList::add)).collect(Collectors.toList());
CompletableFuture.allOf(completableFutureList.toArray(new CompletableFuture[completableFutureList.size()])).get();
But the issue is, their backend cannot handle all the requests at once, so some requests fail. So they asked to do API calls with 1 second delay between each call.
How can I add 1 second delay between each call here?