2

私はサイクロプス反応を非同期再試行で使い始めています。私はまだそれで少し迷っています。

SimpleReact を使用してサーバーからのタイムアウトをシミュレートしていますが、次のようなタイムアウトを受け取ることはありません。

private List<Object> executeParallel() {
    List<Object> result = new SimpleReact(mainThreadPool)
            .of(getSupplier())
            .withRetrier(new AsyncRetryExecutor(retryThreadPool)
                    .abortIf((t) -> !TimeoutException.class.isAssignableFrom(t.getClass()))
            )
            .retry(retrySupplier())
            .block()
            .collect(Collectors.toList());
    return result;
}

private Supplier getSupplier() {
    return () -> someOperationThatTimesOut();
}

private Function<Supplier, Object> retrySupplier() {
    return supplier -> supplier.get();
}

そこに欠けているものは何ですか?

4

1 に答える 1

1

このバージョンは動作します

 AtomicInteger count = new AtomicInteger(0);

@Test
public void executeParallel() {
    List<Object> result = new SimpleReact(Executors.newFixedThreadPool(1))
            .of(getSupplier())
            .withRetrier(new AsyncRetryExecutor(Executors.newScheduledThreadPool(1))
            .retry(Supplier::get)
            .block()
            .collect(Collectors.toList());
    System.out.println(result);
}

private Supplier<String> getSupplier() {
    return () -> {
        System.out.println("Attempt " + count.incrementAndGet());
        if(count.get()<4)
            throw ExceptionSoftener.throwSoftenedException(new TimeoutException());
        return "success";
    };
}

プリントアウトします

Attempt 1
Attempt 2
Attempt 3
Attempt 4
[success]

async-retrier で abortIf は必要ないと思いますが、someOperationThatTimesOut() の内部で何が行われているのかわかりません - それがここでの鍵かもしれません。

于 2016-11-17T11:42:56.437 に答える