CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-quarkus--quarkus-smallrye-fault-tolerance

Build fault-tolerant network services

Pending
Overview
Eval results
Files

timeout-strategies.mddocs/

Timeout Strategies

Method execution timeout controls that prevent hanging operations by enforcing maximum execution time limits.

Capabilities

Basic Timeout

Standard timeout functionality with configurable time limits and units.

@Timeout(
    value = 5,
    unit = ChronoUnit.SECONDS
)
public ReturnType timedMethod() throws Exception;

Parameters

  • value - Timeout duration (default: 1)
  • unit - Time unit for timeout (default: SECONDS)

Usage Example

@ApplicationScoped
public class ExternalServiceClient {
    
    // HTTP call with 5-second timeout
    @Timeout(value = 5, unit = ChronoUnit.SECONDS)
    public ApiResponse callExternalApi(String endpoint) throws TimeoutException {
        return httpClient.get(endpoint);
    }
    
    // Database query with short timeout
    @Timeout(value = 2, unit = ChronoUnit.SECONDS)
    public List<Record> quickQuery(String sql) throws SQLException, TimeoutException {
        return database.query(sql);
    }
    
    // Long-running operation with extended timeout
    @Timeout(value = 30, unit = ChronoUnit.SECONDS)
    public ProcessingResult processLargeFile(File file) throws TimeoutException {
        return fileProcessor.process(file);
    }
}

Timeout with Other Strategies

Combining timeout with retry, circuit breaker, and fallback patterns.

@Timeout(value = 3, unit = ChronoUnit.SECONDS)
@Retry(maxRetries = 2)
@Fallback(fallbackMethod = "timeoutFallback")
public ReturnType resilientTimedMethod();

Usage Example

@ApplicationScoped
public class WeatherService {
    
    // Weather API with timeout, retry, and fallback
    @Timeout(value = 4, unit = ChronoUnit.SECONDS)
    @Retry(maxRetries = 3, delay = 1000)
    @Fallback(fallbackMethod = "getDefaultWeather")
    public WeatherData getCurrentWeather(String city) throws TimeoutException {
        return weatherApiClient.fetchWeather(city);
    }
    
    public WeatherData getDefaultWeather(String city) {
        return WeatherData.defaultFor(city);
    }
    
    // Payment processing with strict timeout
    @Timeout(value = 10, unit = ChronoUnit.SECONDS)
    @CircuitBreaker(requestVolumeThreshold = 5, failureRatio = 0.3)
    public PaymentResult processPayment(PaymentRequest request) throws TimeoutException {
        return paymentGateway.processPayment(request);
    }
}

Types

Timeout Core Types

// Time units for timeout configuration
enum ChronoUnit {
    NANOS, MICROS, MILLIS, SECONDS, MINUTES, HOURS, HALF_DAYS, DAYS
}

// Timeout exception
class TimeoutException extends Exception {
    public TimeoutException(String message);
    public TimeoutException(String message, Throwable cause);
}

Install with Tessl CLI

npx tessl i tessl/maven-io-quarkus--quarkus-smallrye-fault-tolerance

docs

asynchronous-strategies.md

bulkhead-strategies.md

circuit-breaker-strategies.md

configuration.md

fallback-strategies.md

index.md

programmatic-api.md

rate-limiting-strategies.md

retry-strategies.md

timeout-strategies.md

tile.json