我想在一段时间内失败时重试我的函数调用。最好的方法是什么。这会正常工作吗。
CompletableFuture.runAsync(() -> {
for (int i = 0; i < 3; i++) {
try {
dndService.initateDNDRequest(transactionId, circle, category, "PREPAID");
break;
} catch (Exception e) {
try {
TimeUnit.SECONDS.sleep(10);//wait for few minutes while next attempt
} catch (InterruptedException e1) {
LOGGER.error("Error while retrying request for DND.");
}
LOGGER.error("Request retry for DND count"+i);
}
}
}, executor);