Skip to content

Java `Executor` that makes it easy to have tasks retry if they fail

License

Notifications You must be signed in to change notification settings

mrhampson/RetryExecutors

Repository files navigation

Build Status

RetryExecutors

Java Executor that makes it easy to have tasks retry if they fail

Motivation

One use case for this is to deal with rate limited APIs were you might need to have your request back-off for a while until the limit is up

Getting Started

  1. Create a RetryExecutor RetryExecutor retryExecutor = new RetryExecutor(executorService); It delegates to the ScheduledExecutorService you pass it to run its task
  2. Create a Runnable and annotate with the desired RetryStrategy
    @RetryWithFixedDelay(delay = 1, delayUnit = TimeUnit.SECONDS, maxTries = 10)
    class MyRunnable implements Runnable { }
    
    // or...
    
    @RetryWithExponentialDelay(multiplier = 2, initialDelay = 1, initialDelayUnit = TimeUnit.SECONDS, maxTries = 5)
    class MyRunnable implements Runnable { }
    
    // or...
    @RetryWithCustomDelay(retryStrategy = MyCustomRetryStrategyImpl.class)
    class MyRunnable implements Runnable {   
    A working implementation is shown in the unit tests in the source.
  3. Run the Runnable on the RetryExecutor and it will execute according to the policy noted in the annotation The RetryExecutor also lets you run an unannotated Runnables as well

Using in your project

Can include this in your project using JitPack https://jitpack.io/docs/#building-with-jitpack

About

Java `Executor` that makes it easy to have tasks retry if they fail

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages