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

建立网站是很多企业开始进行网络营销的第一步石家庄网络关键词排名

建立网站是很多企业开始进行网络营销的第一步,石家庄网络关键词排名,织梦网站名称,免费的黄台app下载春天猫rtsy好的#xff0c;这实际上与冬天无关#xff0c;众所周知#xff0c;冬天已经到了 。 它与Spring Retry有关#xff0c;Spring Retry是一个小的Spring框架库#xff0c;它使我们可以向应重试的任何任务添加重试功能。 这里有一个很好的教程 #xff0c;解释了如… 春天猫rtsy 好的这实际上与冬天无关众所周知冬天已经到了 。 它与Spring Retry有关Spring Retry是一个小的Spring框架库它使我们可以向应重试的任何任务添加重试功能。 这里有一个很好的教程 解释了如何设置简单的重试和恢复。 它很好地解释了如何添加spring-retry依赖项 使用Retryable和Recover批注以及将RetryTemplate与简单策略一起使用。 当我们实际上想根据异常的类型应用不同的重试行为时我想讲的是一个稍微复杂的情况。 这是有道理的因为我们可能知道某些异常是可恢复的而某些异常是不可恢复的因此尝试从异常中恢复并没有太大的意义。 为此有一个特定的重试策略实现称为ExceptionClassifierRetryPolicy 与Spring RetryTemplate一起使用 。 假设我们只能从IO异常中恢复并跳过所有其他异常 。 我们将创建三个类来扩展RetryCallback并创建一个类来扩展RecoveryCallback以更好地显示内部发生的情况 private class SuccessCallback implements RetryCallbackBoolean, RuntimeException {Overridepublic Boolean doWithRetry(RetryContext context) throws RuntimeException {System.out.println(Success callback: attempt context.getRetryCount());return true;}}private class ExceptionCallback implements RetryCallbackBoolean, Exception {Overridepublic Boolean doWithRetry(RetryContext context) throws Exception {System.out.println(Exception callback: attempt context.getRetryCount());throw new Exception(Test Exception);}}private class SpecificExceptionCallback implements RetryCallbackBoolean, IOException {Overridepublic Boolean doWithRetry(RetryContext context) throws IOException {System.out.println(IO Exception callback: attempt context.getRetryCount());throw new IOException(Test IO Exception);}}private class LoggingRecoveryCallback implements RecoveryCallbackBoolean {Overridepublic Boolean recover(RetryContext context) throws Exception {System.out.println(Attempts exhausted. Total: context.getRetryCount());System.out.println(Last exception: Optional.ofNullable(context.getLastThrowable()).orElse(new Throwable(No exception thrown)).getMessage());System.out.println(\n);return false;}} 然后我们设置RetryTemplate 。 我们将使用SimpeRetryPolicy和IOException的固定尝试次数以及一个NeverRetryPolicy 它仅允许对其他所有事物进行初始尝试。 *We want to retry on IOException only.Other Exceptions wont be retried.IOException will be retried three times, counting the initial attempt.*/final ExceptionClassifierRetryPolicy exRetryPolicy new ExceptionClassifierRetryPolicy();exRetryPolicy.setPolicyMap(new HashMapClass? extends Throwable, RetryPolicy() {{put(IOException.class, new SimpleRetryPolicy(3));put(Exception.class, new NeverRetryPolicy());}});retryTemplate.setRetryPolicy(exRetryPolicy); 现在我们需要使用这些回调来演示它们如何工作。 首先成功执行这很简单 // we do not catch anything hereSystem.out.println(\n*** Executing successfull callback...);retryTemplate.execute(new SuccessCallback(), new LoggingRecoveryCallback()); 其输出如下 *** Executing successfull callback... Success callback: attempt 0 然后是异常 // we catch Exception to allow the program to continueSystem.out.println(\n*** Executing Exception callback...);try {retryTemplate.execute(new ExceptionCallback(), new LoggingRecoveryCallback());} catch (Exception e) {System.out.println(Suppressed Exception);}*** Executing Exception callback... Exception callback: attempt 0 Attempts exhausted. Total: 1 Last exception: Test Exception 最后是我们的IOException // we catch IOException to allow the program to continueSystem.out.println(\n*** Executing IO Exception callback...);try {retryTemplate.execute(new SpecificExceptionCallback(), new LoggingRecoveryCallback());} catch (IOException e) {System.out.println(Suppressed IO Exception);}*** Executing IO Exception callback... IO Exception callback: attempt 0 IO Exception callback: attempt 1 IO Exception callback: attempt 2 Attempts exhausted. Total: 3 Last exception: Test IO Exception 如我们所见只有IOException发起了三个尝试。 请注意尝试次数从0开始编号因为执行回调时尝试次数并未耗尽因此上一次尝试次数为2而不是3。 但是在RecoveryCallback上所有尝试均已用尽因此上下文保留3次尝试。 我们还可以看到尝试成功后未调用RecoveryCallback 。 也就是说仅当执行以异常结束时才调用它。 RetryTemplate是同步的因此所有执行都在我们的主线程中进行。 这就是为什么我在调用周围添加了try / catch块的原因以使程序可以毫无问题地运行所有三个示例。 否则重试策略将在上次失败尝试后将异常抛出并停止执行。 还有一个非常有趣的CompositeRetryPolicy 它允许添加几个策略并委托来依次调用它们。 它还可以允许创建相当灵活的重试策略但这本身就是另一个主题。 我认为spring-retry是一个非常有用的库它可以使常见的可重试任务更可预测可测试且更易于实现。 翻译自: https://www.javacodegeeks.com/2017/07/spring-retry-winter-coming.html春天猫rtsy
http://www.zqtcl.cn/news/158828/

相关文章:

  • 网站建设代码编译的问题及解决方案天元建设集团有限公司第六分公司
  • 做亚马逊网站费用深圳好蜘蛛网站建设公司
  • 做网站需要办什么手续html简单网页代码实例
  • 中文网页设计模板免费下载超级优化小说
  • 做网站的流程前端做什么网站建设与管理专业学什么
  • 用wordpress做购物网站西安建设工程网站
  • 响应式网站免费模板下载电商怎么做如何从零开始视频
  • 江西网站开发学校联系我们网站制作
  • 做网站首页图片素材营销网站制作要素
  • 云阳网站建设百度对 wordpress 排名
  • 做电商网站需要多少时间网站建设答辩ppt
  • 营销型网站的案例江苏seo网站排名优化
  • 企业网站 备案 网站名称凡科做视频网站
  • 湘潭建设公司网站杭州网站优化
  • 工信部备案网站网站空间服务商
  • 深圳市企业网站seo营销工具桂林百姓网
  • 网站建设所需材料wordpress nginx配置文件
  • 给企业做网站运营广州制作网站公司
  • 一个网站可以有几个关键词网页游戏制作过程
  • 网站可视化后台桥西区网站建设
  • 个人怎么建设网站北京朝阳区最好的小区
  • 企业应该如何建设网站江苏润祥建设集团网站
  • 沈阳网站建设价格wordpress h1标签
  • 找别人做网站一般注意什么三亚专业做网站
  • 企业营销网站的建设罗湖做网站
  • 百度蜘蛛抓取新网站WordPress20w文章
  • 国际贸易网站有哪些可植入代码网站开发
  • 信息服务平台有哪些网站东莞网站关键词
  • 青岛网站定制手机软件开发和网站开发
  • 网站数据库地址是什么看企业网站怎么做到百度秒收