R - result typepublic interface Timeout<R> extends Policy<R>
TimeoutExceededException if a
timeout is exceeded. Execution interruption is optionally supported.
Asynchronous executions are cancelled by calling cancel on their
underlying future. Executions can internally cooperate with cancellation by checking ExecutionContext.isCancelled().
This policy uses a separate thread on the configured scheduler or the common pool to perform timeouts checks.
The PolicyBuilder.onFailure(EventListener) and PolicyBuilder.onSuccess(EventListener) event
handlers can be used to handle a timeout being exceeded or not.
Note: interruption will have no effect when performing an async execution since the async thread is unknown to Failsafe.
This class is threadsafe.
TimeoutConfig,
TimeoutBuilder,
TimeoutExceededException| Modifier and Type | Method and Description |
|---|---|
static <R> TimeoutBuilder<R> |
builder(Duration timeout)
|
static <R> TimeoutBuilder<R> |
builder(TimeoutConfig<R> config)
Creates a new TimeoutBuilder that will be based on the
config. |
TimeoutConfig<R> |
getConfig()
Returns the
TimeoutConfig that the Timeout was built with. |
static <R> Timeout<R> |
of(Duration timeout)
|
toExecutorstatic <R> TimeoutBuilder<R> builder(Duration timeout)
timeout - the duration after which an execution is failed with TimeoutExceededException.NullPointerException - If timeout is nullIllegalArgumentException - If timeout is <= 0static <R> TimeoutBuilder<R> builder(TimeoutConfig<R> config)
config.static <R> Timeout<R> of(Duration timeout)
Timeout that fails an execution with TimeoutExceededException if
it exceeds the timeout. Alias for Timeout.builder(timeout).build(). To configure additional options
on a Timeout, use builder(Duration) instead.R - result typetimeout - the duration after which an execution is failed with TimeoutExceededException.NullPointerException - If timeout is nullIllegalArgumentException - If timeout is <= 0builder(Duration)TimeoutConfig<R> getConfig()
TimeoutConfig that the Timeout was built with.Copyright © 2022. All rights reserved.