簡體   English   中英

如何設置Spring Retry模板以重試最大嘗試次數:無限

[英]How to set Spring Retry template to retry max attempts: infinite

我想修改數據庫連接創建與Spring重試,如果數據庫在應用程序啟動時關閉,請再次嘗試。 我不想限制重試次數。 我應該如何配置策略來執行此操作。

我當前的代碼(我知道在這種狀態下它限制為100):

SimpleRetryPolicy policy = new SimpleRetryPolicy(100, Collections.singletonMap(Exception.class, true));

// Use the policy...
RetryTemplate template = new RetryTemplate();
template.setRetryPolicy(policy);
Connection conn = template.execute(new RetryCallback<Connection, Exception>() {
    public Connection doWithRetry(RetryContext context) throws Exception {
        return getConnectionFactory().createConnection();
    }
});

我應該如何修改此代碼?

使用AlwaysRetryPolicy而不是SimpleRetryPolicy

但您可能希望在重試之間添加BackOffPolicy以等待。

然后,您可以中斷線程以關閉所有內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM