我想用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();
}
});
我应该如何修改此代码?
最佳答案
使用AlwaysRetryPolicy代替SimpleRetryPolicy.
但是您可能想要添加BackOffPolicy以在重试之间等待.
然后,您可以中断线程以关闭所有程序.
Inm小程序商店
Inm小程序商店收录了最新,最热门的微信小程序和微信小游戏,是国内内容最丰富的集小程序游戏、小程序分发、小程序推广为一体的综合性小程序门户网站之一。
Vultr中文网
最低 $2.5/月 的VPS, 稳定, 可靠