Timeouts allow you to fail an execution with
TimeoutExceededException if it takes too long to complete:
Timeout<Object> timeout = Timeout.of(Duration.ofSeconds(10));
You can create a Timeout that interrupts execution if it times out:
Timeout<Object> timeout = Timeout.builder(Duration.ofSeconds(10)).withInterrupt().build();
If a cancellation is triggered by a
Timeout, the execution is completed with
TimeoutExceededException. See the execution cancellation page for more on cancellation and interruption.
Timeout is composed outside a
RetryPolicy, a timeout occurrence will cancel any inner retries:
Timeout is composed inside a
RetryPolicy, a timeout occurrence will not automically cancel any outer retries:
When an async executions times out, Failsafe still waits until the execution completes, either through interruption or naturally, before recording a
TimeoutExceededException. This avoids the risk of retrying while the original execution is still running, which ultimately could lead to numerous abandoned executions running in numerous threads.
builder.onFailure(e -> log.error("Connection attempt timed out", e.getException()));
Or when an execution completes and the timeout is not exceeded:
builder.onSuccess(e -> log.info("Execution completed on time"));
Since the async integration methods involve external threads, which Failsafe has no knowledge of, these executions cannot be directly cancelled or interrupted by a Timeout. But, these executions can still cooperate with a Timeout cancellation.