2017-03-17 65 views
0

我希望我的RetryTemplate具有300000毫秒的延遲 - 5分鐘乘以每次嘗試1.1次。但是,它只會延遲下一次嘗試30秒。這裏有一個簡單的例子:如果未設置maxDelay,彈簧重試模板過早啓動

@Service 
public class Foo { 
    private static final Logger log = Logger.getLogger(Foo.class); 

    @Retryable(value = Exception.class, 
      backoff = @Backoff(delay = 300000, multiplier = 1.1)) 
    public void run() throws Exception { 
     new Bar().run(); 
    } 

    @Recover 
    void recover(Exception e) { 
     log.error("e", e); 
    } 
} 

public class Bar { 
    private static final Logger log = Logger.getLogger(Bar.class); 

    public void run() throws Exception{ 
     log.info("hier"); 
     throw new Exception(); 
    } 
} 

@Bean 
CommandLineRunner runner() { 
    return (String[] a) -> { 
      scheduler.schedule(() -> { 
       try { 
        retryTemplate.execute(arg -> { 
         foo.run(); 
         return null; 
        }); 
       } catch (Exception e) { 

       } 
      }, 1 , TimeUnit.SECONDS); 
    }; 
} 

日誌在這些時間做:

2017-03-17 13:25:08.439 INFO 6500 --- [ 
2017-03-17 13:25:38.439 INFO 6500 --- [ 
2017-03-17 13:26:08.440 INFO 6500 --- [ 
2017-03-17 13:26:08.444 ERROR 6500 --- [ 

如果我使用它,它不會有所作爲有或沒有調度程序(這是因爲原始代碼需要最初的延遲。)

現在,如果我一個MAXDELAY添加到@Backoff

@Backoff(delay = 300000, multiplier = 1.1, maxDelay = 1000000000) 

它的工作原理完全按預期 - 5 *1.1分鐘等後5分鐘後發射,然後。但是閱讀的Javadoc @Backoff - MAXDELAY,它則默認表示爲0,如果低於延緩

/** 
    * The maximimum wait (in milliseconds) between retries. If less than the 
    * {@link #delay()} then ignored. 
    * 
    * @return the maximum delay between retries (default 0 = ignored) 
    */ 
    long maxDelay() default 0; 

有什麼我沒聽懂被忽略?似乎maxDelay默認爲30秒,這與javadoc解釋的完全不同。

二手春重試版本是1.1.3

回答

1

它在Javadoc中的錯誤 - 看到代碼here

policy.setMaxInterval(max > min ? max : ExponentialBackOffPolicy.DEFAULT_MAX_INTERVAL); 

public static final long DEFAULT_MAX_INTERVAL = 30000L; 
+0

那滿滿的..謝謝! – baao