Spring retry

来自ling
跳转至: 导航搜索
public interface IProcess {
   @Retryable( include = NullPointerException.class, maxAttempts = 5, backoff = @Backoff( delay = 1000 ) )
   void doWork();
   @Retryable( maxAttempts = 10, backoff = @Backoff( delay = 500, multiplier = 2.3, maxDelay = 20000 ) )
   void doWork2() throws Exception;
   @Recover//恢复程序
   void finishRetry();
}

二、注解含义

  • @Retryable
  1. Include:需要重试的异常,如果include和excludes都不存在,那么所有的异常都要重试。
  2. maxAttempts最大重试次数
  • @Backoff
  1. Delay统一的延迟时间
  2. maxDelay重试的最大等待时间
  3. Multiplier一个乘数,用来计算下一个延迟时间