【发布时间】:2017-03-11 15:29:57
【问题描述】:
我正在使用来自 https://github.com/nurkiewicz/async-retry 的 RetryExecutor
下面是我的代码:
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(10);
RetryExecutor retryExecutor = new AsyncRetryExecutor(executorService)
.retryOn(IOException.class)
.withExponentialBackoff(500, 2)
.withMaxDelay(5_000) // 5 seconds
.withUniformJitter()
.withMaxRetries(5);
我已经向 retryExecutor 提交了一些任务。
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);
}
});
现在,我如何等待所有提交的任务完成? 我想等到所有重试都完成(如果有的话)。
不要以为会像executorService.shutdown()那么简单;
【问题讨论】:
标签: java multithreading scheduledexecutorservice