use*_*543 4 java spring multithreading jdbc 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<Connection, Exception>() {
public Connection doWithRetry(RetryContext context) throws Exception {
return getConnectionFactory().createConnection();
}
});
Run Code Online (Sandbox Code Playgroud)
我应该如何修改此代码?
使用AlwaysRetryPolicy代替SimpleRetryPolicy。
但是您可能想要添加一个BackOffPolicy在重试之间等待的时间。
然后,您可以中断线程以关闭所有程序。
| 归档时间: |
|
| 查看次数: |
1886 次 |
| 最近记录: |