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