In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "what are the ways to configure Sisyphus in the Java retry framework". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the ways to retry the Sisyphus configuration of the Java framework?"
1. Overview of functional configuration
For more convenient configuration, the Retryer class provides a lot of information that can be configured.
1.1 default configuration / * * default configuration Test * / public void defaultConfigTest () {Retryer.newInstance () .condition (RetryConditions.hasExceptionCause ()) .retryWaitContext (RetryWaiter.retryWait (NoRetryWait.class). Context ()) .maxAttempt (3) .recover (Recovers.noRecover ()) .callable (new Callable () {@ Override public String call () throws Exception {System.out.println ("called...") Throw new RuntimeException ();}}. RetryCall ();}
Is equivalent to the following code:
Public void helloTest () {Retryer.newInstance () .callable (new Callable () {@ Override public String call () throws Exception {System.out.println ("called..."); throw new RuntimeException ();}}) .retryCall () } 2. Method description 2.1 condition
Retry the triggered condition, you can specify multiple conditions.
The default is to throw an exception.
2.2 retryWaitContext
Retry the waiting policy, you can specify more than one.
The default is not to wait.
2.3 maxAttempt
Specify the maximum number of retries, including the first execution.
Default value: 3 times.
2.4 listen
Specifies the listening implementation of the retry. The default is no listening.
2.5 recover
When the retry is complete and the retry conditions are still met, you can specify a recovery strategy.
Restore is not done by default.
2.6 callable
The method to be retried.
2.7 retryCall
Triggers a retry execution.
3. Detailed introduction of the interface 3.1 interface and its implementation
For all interfaces, you can view the corresponding subclass instances directly.
3.2 user customization
Based on the flexibility of substitution, users can implement interfaces and define implementations that are more in line with their business.
3.3 sisyphus comments
Configuration is highly flexible, but it is not as simple and flexible as annotations for developers.
Therefore, this framework also implements annotation-based retry.
4. Specification of design
Ensure the unity of interfaces and annotations.
4.1 maven introduces ${project.groupId} sisyphus-annotation ${project.version}
Notes:
There are two main core annotations.
4.2 Retry
Used to specify the relevant configuration for the retry.
/ * retry Note * 1. The actual need can only be put on the method. * 2. If placed on an interface, do all subclasses take effect? For simplicity and clarity, this implementation is not provided. * 3. Maintain the consistency of comments and interfaces. {@ link com.github.houbb.sisyphus.api.core.Retry} interface * @ author binbin.hou * @ since 0.0.3 * / @ Documented @ Inherited @ Target (ElementType.METHOD) @ Retention (RetentionPolicy.RUNTIME) @ RetryAble (DefaultRetryAbleHandler.class) public @ interface Retry {/ * retry class implementation * @ return retry * @ since 0.0.5 * / 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.