Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Spring-Retry

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to use Spring-Retry, in view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Brief introduction of 1 Spring-Retry

In some daily scenarios, there are many operations that require retry. Spring-retry is a spring-based retry framework provided by spring, which is very simple and easy to use.

Application in 2 Spring

1 Import maven coordinates

Org.springframework.retry spring-retry 1.2.2.RELEASE 2 add called class

@ Slf4jpublic class RetryDemo {public static boolean retryMethod (Integer param) {int I = new Random () .nextInt (param); log.info ("randomly generated number: {}", I); if (1 = = I) {log.info ("is 1, returns true."); return true;} else if (I)

< 1) { log.info("小于1,抛出参数异常."); throw new IllegalArgumentException("参数异常"); } else if (i >

1 & & I < 10) {log.info ("> 1, < 10, throw parameter exception."); return false;} else {/ / for other log.info ("> 10, throw custom exception."); throw new RemoteAccessException ("> 10, throw custom exception");} 3 add test class

@ Slf4jpublic class SpringRetryTest {/ * retry interval ms, default 1000ms * / private long fixedPeriodTime = 1000L; / * maximum number of retries, default is 3 * / private int maxRetryTimes = 3; / * indicates which exceptions need to be retried * key must be a subclass of Throwable exception Class

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report