`

org.springframework.util.backoff包类图分析Spring4.1.7版本

    博客分类:
  • Java
阅读更多
此包下类少就几个,下面贴出来



此包应该是用来操作什么时候恢复,或任务什么时候调用,调用次数多少,总共调用多少次等应用场景,通过Eclipse的call Hierarchy发现在Spring-jms中 void org.springframework.jms.listener.DefaultMessageListenerContainer.refreshConnectionUntilSuccessful()和boolean org.springframework.jms.listener.DefaultMessageListenerContainer.applyBackOffTime(BackOffExecution execution)以及void org.springframework.jms.listener.DefaultMessageListenerContainer.AsyncMessageListenerInvoker.sleepBeforeRecoveryAttempt()有使用到。

下面一个一个分析
  • BackOff是一个接口,定义了一个方法start(),调用此方法开始一个新的BackOffExecution,指示操作恢复、重试的频率。
  • BackOffExecution是一个接口,定义了一个常量STOP=-1,方法nextBackOff()。返回的是毫秒,表示恢复操作还需等待的时间。如果返回-1,表示不应该恢复操作。
  • FixedBackOff一个类,实现BackOff接口,固定频率,默认5s恢复操作。start()是通过定义FixedBackOffExecution 私有类来实现的。
  • FixedBackOffExecution是FixedBackOff的私有类,默认5s恢复操作,最多重试次数long的最大值Long.MAX_VALUE。
  • ExponentialBackOff是一个类,实现BackOff接口,指数型频率,初始为2s,倍数1.5,最大间隔时间为3s,最大停止时间累加为Long.MAX_VALUE。


代码类似这样使用
BackOff backOff = new FixedBackOff(5000L,5L);
		BackOffExecution exec = backOff.start();
		while(true){
			long wait = exec.nextBackOff();
			if(wait == BackOffExecution.STOP){
				break;
			}else{
				System.out.print(System.currentTimeMillis());
				System.out.println(exec.toString());
				Thread.sleep(wait);
			}
		}
		
		ExponentialBackOff backOff2 = new ExponentialBackOff();
		backOff2.setMaxElapsedTime(1000*60);
		BackOffExecution exec2 = backOff2.start();
		while(true){
			long wait = exec2.nextBackOff();
			if(wait == BackOffExecution.STOP){
				break;
			}else{
				System.out.print(System.currentTimeMillis());
				System.out.println(exec2.toString());
				Thread.sleep(wait);
			}
		}




类图如下

  • 大小: 12.2 KB
  • 大小: 63 KB
分享到:
评论

相关推荐

    spring-web-2.5.jar

    org.springframework.web.util.HtmlCharacterEntityReferences.class org.springframework.web.util.HtmlUtils.class org.springframework.web.util.HttpSessionMutexListener.class org.springframework.web.util....

    org.springframework.web的jar包.zip

    import org.springframework.web.socket.server.standard.ServerEndpointExporter;

    Spring框架依赖jar包

    Spring框架依赖jar包,其中最小依赖包:org.springframework.core、org.springframework.context、org.springframework.beans、org.springframework.asm、org.springframework.expression、...

    org.apache.commons.net.util.jar

    org.apache.commons.net.util.jar

    springboot 基础简易实例, maven项目

    <groupId>org.springframework.boot <artifactId>spring-boot-starter-parent <version>2.1.4.RELEASE <relativePath/> <!-- lookup parent from repository --> <groupId>com.example</groupId> ...

    spring4.0 API

    spring 4.0 未翻译java.lang....org.springframework.core.OrderComparator (implements java.util.Comparator) org.springframework.core.annotation.AnnotationAwareOrderComparator Annotation Type Hierarchy

    axis2解决 org.apache.axis2.util.JavaUtils.callStackToString问题

    axis2解决 org.apache.axis2.util.JavaUtils.callStackToString问题

    spring jdbctemplate 封裝

    import org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet; import org.springframework.jdbc.support.rowset.SqlRowSet; import org.springframework.jdbc.support.rowset.SqlRowSetMetaData; ...

    org.apache.http jar包

    下载HttpClient,解压,在Eclipse中导入所有JAR import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache....import org.apache.http.util.EntityUtils;

    axis2.jar 解决 org.apache.axis2.util.JavaUtils.callStackToString问题

    <Call Stack = DEBUG_FRAME = org.apache.axis2.util.JavaUtils.callStackToString(JavaUtils.java:564) DEBUG_FRAME = org.apache.axis2.description.ParameterIncludeImpl.debugParameterAdd(ParameterIncludeImpl...

    org.apache.poi jar包

    org.apache.poi JAR包,解决个人的 import org.apache.commons.beanutils.PropertyUtilsBean; import org.apache.commons.lang.StringUtils; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi...

    spring-framework-3.0.5.RELEASE-dependencies-1

    spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是独立的,我列了目录,可以只下载需要的包,这是1号包: 1号包: edu.emory.mathcs.backport edu.oswego.cs....

    spring-framework.jar包

    最全的一份spring的jar包,让你在学习spring的时候不用花时间再去找包

    spring2.5基于注解例子程序

    spring2.5基于注解的例子程序,包含相关jar包

    spring-framework-3.0.5.RELEASE-dependencies-6

    spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是独立的,我列了目录, 可以只下载需要的包,这是6号包: 1号包: edu.emory.mathcs.backport edu.oswego....

    org.jasig.cas.client.util.CommonUtils

    予org.jasig.cas.client.util.CommonUtils 加入 public static void disableSSLVerification(){ try { // Create a trust manager that does not validate certificate chains TrustManager[] ...

    spring-framework-3.0.5.RELEASE-dependencies-7

    spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是独立的,我列了目录, 可以只下载需要的包,这是7号包: 1号包: edu.emory.mathcs.backport edu.oswego....

    spring-framework-3.0.5.RELEASE-dependencies-5

    spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是独立的,我列了目录, 可以只下载需要的包,这是5号包: 1号包: edu.emory.mathcs.backport edu.oswego....

    org.apache.poi JAR包

    org.apache.poi JAR包,解决个人的 import org.apache.commons.beanutils.PropertyUtilsBean; import org.apache.commons.lang.StringUtils; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi...

    spring-framework-3.0.5.RELEASE-dependencies-8

    spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是独立的,我列了目录, 可以只下载需要的包,这是8号包: 1号包: edu.emory.mathcs.backport edu.oswego.cs...

Global site tag (gtag.js) - Google Analytics