Class RetryTask

java.lang.Object
io.atlassian.fugue.retry.RetryTask
All Implemented Interfaces:
Runnable

public class RetryTask extends Object implements Runnable
A Runnable which wraps the apply method of another Runnable and attempts it a fixed number of times. This class can be used when a task is known to be prone to occasional failure and other workarounds are not known.
See Also:
  • Field Details

  • Constructor Details

    • RetryTask

      public RetryTask(Runnable task, int tries)
      An instance that does nothing before retrying and ignores exceptions that occur.
      Parameters:
      task - to run, must not be null
      tries - number of times to attempt to run task, must be posititve
    • RetryTask

      public RetryTask(Runnable task, int tries, ExceptionHandler handler)
      An instance that does nothing before retrying.
      Parameters:
      task - to run, must not be null
      tries - number of times to attempt to run task, must be positive
      handler - reacts to exceptions thrown by the wrapped task, must not be null
    • RetryTask

      public RetryTask(Runnable task, int tries, ExceptionHandler handler, Runnable beforeRetry)

      Constructor for RetryTask.

      Parameters:
      task - to run, must not be null
      tries - number of times to attempt to run task, must be positive
      handler - reacts to exceptions thrown by the wrapped task, must not be null
      beforeRetry - runs before each retry, must not be null
  • Method Details

    • run

      public void run()
      Attempt to run the wrapped Runnable tries number of times. Any exceptions thrown will be ignored until the number of attempts is reached. If the number of attempts is reached without success, the most recent exception to be thrown will be rethrown.
      Specified by:
      run in interface Runnable