javascript
java retry 设置上限_java-如何设置Spring Retry模板重试最大尝试次数:无限
我想用Spring Retry修改數據庫連接的創建,以便在應用程序啟動時數據庫關閉時再試一次.我不想限制重試次數.我應該如何配置策略來做到這一點.
我當前的代碼(我知道在這種狀態下它限制為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() {
public Connection doWithRetry(RetryContext context) throws Exception {
return getConnectionFactory().createConnection();
}
});
我應該如何修改此代碼?
解決方法:
使用AlwaysRetryPolicy代替SimpleRetryPolicy.
但是您可能想要添加BackOffPolicy以在重試之間等待.
然后,您可以中斷線程以關閉所有程序.
標簽:multithreading,jdbc,spring-retry,spring,java
來源: https://codeday.me/bug/20191109/2012890.html
總結
以上是生活随笔為你收集整理的java retry 设置上限_java-如何设置Spring Retry模板重试最大尝试次数:无限的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [云炬ThinkPython阅读笔记]2
- 下一篇: [云炬ThinkPython阅读笔记]2