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

怎么做私人彩票网站中企动力做销售的经历

怎么做私人彩票网站,中企动力做销售的经历,绵阳做网站的有哪些,专做机酒的网站在我从事的每个项目中#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://wiki.neutronadmin.com/news/412029/

相关文章:

  • 荣耀商城官网网站广州网页设计机
  • 网页设计网站简单静态模板深圳网页制作模板
  • 华为弹性云做网站专门做女性产品的网站
  • 网站改版的宣传词奢侈品网站建设方案
  • 广州网站建设代理做网站需要注意的
  • 专业建站分销商城百度网页游戏中心
  • 焦作网站建设公司哪家好贵阳外发加工网
  • 网站优化推广seo公司网站怎么添加百度商桥
  • 最好的购物网站架设仿冒网站挂马
  • 包装纸箱公司怎么做网站seo服务公司上海
  • 微信视频网站怎么做怎么做游戏网站
  • 锦州网站建设品牌wordpress 做大型网站吗
  • 网站服务器 安全桂林小程序开发定制
  • 云南网站定制开发黄陂机械加工网
  • 公司网站做的一样算不算侵权6网络运维服务方案
  • 北京建设网站的公司哪家好深圳推广系统多少钱
  • 青海建设厅网站通知云南省城乡建设厅网站
  • 什么外贸网站做箱包好大连手机自适应网站制作费用
  • 长春建立一个网站需要多少钱?做黑彩网站赚钱吗
  • 专业做旅游网站的公司施工企业的定义
  • 建e网站官网案例做网站推广怎样才能省钱
  • 创建电子商务网站的步骤关于公司网络优化方案
  • 如何提高网站关键词排名济南做手机网站
  • 宣传型网站建设如何自己做一个网站
  • 如何自学网站建设书籍做美食下载什么网站
  • 想建设个网站怎么赚钱新建的网站百度搜索不到
  • 中国水土保持与生态环境建设网站wordpress建商城
  • 中心网站建设方法建筑工具网站
  • 昆山做网站费用上海崇明网站建设
  • 深圳网站建设自己人网站售后服务内容