Ich verwende RetryExecutor aus: https://github.com/nurkiewicz/async-retryRetryExecutor: Wie warten, bis alle Aufgaben abgeschlossen sind?
Below id mein Code:
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(10);
RetryExecutor retryExecutor = new AsyncRetryExecutor(executorService)
.retryOn(IOException.class)
.withExponentialBackoff(500, 2)
.withMaxDelay(5_000) // 5 seconds
.withUniformJitter()
.withMaxRetries(5);
Ich habe ein paar Aufgaben zu retryExecutor vorgelegt.
retryExecutor.getWithRetry(ctx -> {
if(ctx.getRetryCount()==0)
System.out.println("Starting download from : " + url);
else
System.out.println("Retrying ("+ctx.getRetryCount()+") dowload from : "+url);
return downloadFile(url);
}
).whenComplete((result, error) -> {
if(result!=null && result){
System.out.println("Successfully downloaded!");
}else{
System.out.println("Download failed. Error : "+error);
}
});
Nun, wie warte ich auf alle übertragenen Aufgaben zu beenden? Ich möchte warten, bis alle Versuche abgeschlossen sind (falls vorhanden).
glaube nicht, dass es so einfach sein wird wie executorService.shutdown();
Bitte fügen Sie eine Erklärung auf Ihre Antwort: [? Wie kann ich eine gute Antwort schreiben] (https://stackoverflow.com/help/how-to-answer) –