当前位置: 首页 > news >正文

上海网站开发学校有哪些中山手机网站建设

上海网站开发学校有哪些,中山手机网站建设,中文wordpress,陕西城乡住房建设厅网站新增操作 失败后重试在我从事的每个项目中#xff0c;始终需要某些功能#xff1a;重试操作。 通常#xff0c;这是关于通过网络的呼叫#xff0c;该呼叫可能一次失败#xff0c;但随后会成功。 它可能涉及许多其他内容#xff0c;主要包括与另一个系统的通信#xff08… 新增操作 失败后重试 在我从事的每个项目中始终需要某些功能重试操作。 通常这是关于通过网络的呼叫该呼叫可能一次失败但随后会成功。 它可能涉及许多其他内容主要包括与另一个系统的通信无论是否通过网络。 它的功能你绝对需要在大多数应用中特别是如果你想他们是高可用性 如这里指出的 例如。 每次我必须在项目中引入此功能时我都会检查我们已导入的标准库没有这样的东西。 因此我总是最终将我以前的项目中的同一段代码复制粘贴。 我什至不记得我是什么时候第一次介绍它的但是从那以后我就在“旅行”。 所以这里是 /*** Class that provides retrying functionality. Example:* p/p* code* CallableString callable new CallableString() {..};* String result RetryableOperation.create(callable).retry(5, IOException.class);* /code** param T the return type of the operation*/ public class RetryableOperationT {private CallableT callable;private Runnable runnable;private boolean exponentialBackoff;private int backoffInterval 500;/*** Create a retryable operation based on a Callable instance. The return* type of retry(..) is the type parameter of the Callable instance.** param callable* return* a new instance of RetryableOperation*/public static T RetryableOperationT create(CallableT callable) {return new RetryableOperationT().withCallable(callable);}/*** Creates a retryable operation based on a Runnable instance. In this case* the retry(..) method always returns null.** param runnable* return* a new instance of RetryableOperation*/public static RetryableOperation? create(Runnable runnable) {return new RetryableOperationObject().withRunnable(runnable);}/*** Retries the operation. Retrying happens regardless of the exception thrown.** param retries* number of retries before the exception is thrown to the caller* param exceptions* the operation will be retried only if the exception that occurs is one of the* exceptions passed in this array* return* the result of the operation (null if Runnable is used instead of Callable)* throws Exception* the exception that occurred on the last attempt*/public T retry(int retries, Class? extends Exception... exceptions) throws Exception {if (callable null runnable null) {throw new IllegalStateException(Either runnable or callable must be set);}SetClass? extends Exception retryFor new HashSetClass? extends Exception();retryFor.addAll(Arrays.asList(exceptions));for (int i 0; i retries; i) {try {if (exponentialBackoff i 0) {int sleepTime (int) ((Math.pow(2, i) - 1) / 2) * backoffInterval;Thread.sleep(sleepTime);}if (callable ! null) {return callable.call();} else if (runnable ! null) {runnable.run();return null;}} catch (Exception e) {if (retryFor.isEmpty() || retryFor.contains(e.getClass())) {if (i retries - 1) {throw e;}} else {// if the exception is not the expected one, throw it immediatelythrow e;}}}// cant be reached - in case of failure on the last iteration the exception is rethrownreturn null;}private RetryableOperationT withCallable(CallableT callable) {this.callable callable;return this;}private RetryableOperationT withRunnable(Runnable runnable) {this.runnable runnable;return this;}public RetryableOperationT withExponentialBackoff() {this.exponentialBackoff true;return this;} } 1 这很简单但是效果很好。 您可以重试每个失败也可以重试特定的异常您不想重试NullPointerException但是必须配置适当的超时然后重试网络故障 Result result op.retry(3);...Result result op.retry(3, IOException.class); 我什至曾建议番石榴将其包含在内然后再看其他类似的提案但据我所知番石榴或apache commons中都没有这种功能。 而且我不会创建一个新的github项目因为那将需要在maven Central中管理一个条目而对于单个实用程序类来说这是一项很大的工作。 当然还有其他解决方法它们具有更大的API和占用空间- 重试番石榴扩展和最近提取为单独的项目spring-retry 。 它们值得检查并且具有要导入的Maven依赖项。 无论选择什么选项请检查它是否支持匿名功能自Java 8起。 它可能会自动执行但仍会检查。 关键是要通过一个非常简单的API来提供此功能以便您可以避免用户可避免的故障-必须重试几次对外部系统的调用。 翻译自: https://www.javacodegeeks.com/2015/10/retryable-operations.html新增操作 失败后重试
http://www.yutouwan.com/news/321331/

相关文章:

  • html的制作网站的优点什么是网站降权处理
  • 大型网站建设服务公司网站建设课程设计百度文库
  • 企业网站建设大概需要多少钱危险网站怎么解除
  • 河南夏邑网站建设免费站推广网站不用下载
  • 国外专门做旅行社的网站视频网站 移动 模板
  • 教研室网站建设wordpress搜索无效
  • 国内人做韩国网站一般都卖什么东西大学生网页设计个人主页
  • 全网营销式网站如何注册公司多少钱
  • 网络公司怎么做网站成都网站开发环球中心
  • 企业网站资料大全网线制作实训总结
  • 网站建设基础实训报告住房建设部官方网站专家注册
  • 网站制作怎样快速wordpress4.8.3中文
  • 做网站换域名电脑要登入国外的网站应该怎么做
  • 网上做平面设计兼职不错的网站网站制作 符合百度
  • 西安网站制作sxyun期末网页设计作业及素材
  • 想做淘宝 网站怎么做大型平台网站开发
  • 男和男做那个视频网站wordpress怎么加菜单
  • 做网站刷点击最新新闻十条
  • 怎样投网站广告哪里有做营销型网站的公司
  • 网站备案需要哪些资料未来销售最好的行业
  • 简要说明开发网站的步骤网站建设方案及报
  • 汕头网站快速优化排名wordpress apply_filter
  • 网站建设的目标和需求分析wordpress表情无插件
  • 网站开发先写后端先写前端江苏住房城乡建设网站
  • 网站推广方法有哪些石家庄造价信息网官网
  • 域名备案网站建设方案ui设计好学吗?要学多久
  • php mysql 企业网站源码前台登录 wordpress
  • 网站建设高端设计网络推广关键词优化公司
  • 建站公司技术服务费西安百度竞价外包
  • 清远医院网站建设方案wordpress读法