“重试"的设计模式失败的逻辑?

编程入门 行业动态 更新时间:2024-10-08 13:36:45
本文介绍了“重试"的设计模式失败的逻辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在编写一些重新连接逻辑,以定期尝试与发生故障的远程端点建立连接.本质上,代码如下所示:

I'm writing some reconnect logic to periodically attempt to establish a connection to a remote endpoint which went down. Essentially, the code looks like this:

public void establishConnection() { try { this.connection = newConnection(); } catch (IOException e) { // connection failed, try again. try { Thread.sleep(1000); } catch (InterruptedException e) {}; establishConnection(); } }

我已经多次使用与上述类似的代码解决了这个普遍问题,但我对结果很不满意.有没有专门针对这个问题设计的设计模式?

I've solved this general problem with code similar to the above on many occasions, but I feel largely unsatisfied with the result. Is there a design pattern designed for dealing with this issue?

推荐答案

值得一试的图书馆是 Sarge,根据定义的计划自动执行重试.

One library worth checkout out is Sarge, which automatically performs retries according to a defined plan.

更多推荐

“重试"的设计模式失败的逻辑?

本文发布于:2023-11-26 07:42:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633231.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重试   逻辑   模式   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!