Skip to content

ajlane/retry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Retry

javadoc build-status codecov

A utility for automatically retrying failed tasks according to a retry strategy. Built-in strategies include linear and exponential back-off.

If a task fails by throwing an exception, the exception will be suppressed while the task is re-executed. If no more retries are permitted all of the suppressed exceptions will be available via the task's Future.

Tasks can be executed asynchronously by providing a ScheduledExecutionService.

Retry is provided under the Apache License Version 2.0.

Example

Attempts to search twitter for tweets matching a given query. If a TwitterException is thrown, the task will be retried after 5, 10, 20, 40, and 80 seconds, using the exponential back-off strategy.

Future<List<Status>> result =
    Retry.withExponentialBackoff( 5, TimeUnit.SECONDS )
         .when( TwitterException.class )
         .limit( 5 )
         .execute(() ->
            twitter.search( query )
                   .getTweets()
         );

Maven

Retry is available in Maven Central.

<dependency>
  <groupId>au.id.ajlane.retry</groupId>
  <artifactId>retry</artifactId>
  <version>0.0.1</version>
</dependency>

About

Automatic retry and back-off for Java tasks

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages