调用具有指数退避的方法,直到列表不为空
Call a method with exponential back off until the list is not empty
我正在尝试以指数方式调用一个方法,直到 list.size !=0。如何实现?我尝试了以下但没有成功。
public static void main(String[] args) throws InterruptedException {
Mono.defer(() -> myExecution())
.repeatWhenEmpty(Repeat.onlyIf(repeatContext -> true)
.exponentialBackoff(Duration.ofSeconds(1), Duration.ofSeconds(30))
.timeout(Duration.ofSeconds(30))).subscribe();
}
private static <T> Mono<List<String>> myExecution() {
Date date = new Date();
List<String> data = new ArrayList();
if(data.size() !=0) {
return Mono.just(data);
}
System.out.println("Hello = " + new Timestamp(date.getTime()));
return Mono.empty();
}
这有效
public static void main(String[] args) throws InterruptedException {
Mono.defer(() -> myExecution())
.repeatWhenEmpty(Repeat.onlyIf(repeatContext -> true)
.exponentialBackoff(Duration.ofMillis(1000), Duration.ofSeconds(60))
.timeout(Duration.ofSeconds(60))).block();
}
private static <T> Mono<List<String>> myExecution() {
Date date = new Date();
List<String> data = new ArrayList();
if (data.size() != 0) {
return Mono.just(data);
}
System.out.println("Hello = " + new Timestamp(date.getTime()));
return Mono.empty();
}
我正在尝试以指数方式调用一个方法,直到 list.size !=0。如何实现?我尝试了以下但没有成功。
public static void main(String[] args) throws InterruptedException {
Mono.defer(() -> myExecution())
.repeatWhenEmpty(Repeat.onlyIf(repeatContext -> true)
.exponentialBackoff(Duration.ofSeconds(1), Duration.ofSeconds(30))
.timeout(Duration.ofSeconds(30))).subscribe();
}
private static <T> Mono<List<String>> myExecution() {
Date date = new Date();
List<String> data = new ArrayList();
if(data.size() !=0) {
return Mono.just(data);
}
System.out.println("Hello = " + new Timestamp(date.getTime()));
return Mono.empty();
}
这有效
public static void main(String[] args) throws InterruptedException {
Mono.defer(() -> myExecution())
.repeatWhenEmpty(Repeat.onlyIf(repeatContext -> true)
.exponentialBackoff(Duration.ofMillis(1000), Duration.ofSeconds(60))
.timeout(Duration.ofSeconds(60))).block();
}
private static <T> Mono<List<String>> myExecution() {
Date date = new Date();
List<String> data = new ArrayList();
if (data.size() != 0) {
return Mono.just(data);
}
System.out.println("Hello = " + new Timestamp(date.getTime()));
return Mono.empty();
}