Major updates to spring-boot-klock-starter V1.1 Main Functions,
The redis-based spring-boot Distributed Lock component makes it extremely simple and out-of-the-box.
This component is also applicable to spring mvc projects.
Content of this update:
- Service key that supports locking method input parameters
- Service keys can be obtained through annotation.
- Support for Spel to obtain business keys
The usage is as follows:
Scenario Description:
This update mainly solves the problem where the value of the input parameter needs to be locked at the same time and the value of the input parameter is not locked when the value is different;
Out-of-the-box
1. Add the lock starter component dependency
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-klock-starter</artifactId> <version>1.0-SNAPSHOT</version> </dependency>
2.application.properties
Configure the redis link:spring.klock.address=127.0.0.1:6379
3. Add the annotation @ Klock on the method to add the Distributed Lock, for example:
@ Servicepublic class TestService {@ Klock (waitTime = Long. MAX_VALUE) public String getValue (String param) throws Exception {if ("sleep ". equals (param) {// Thread sleep or breakpoint blocking, to achieve the test effect of staying locked. Thread. sleep (1000*50);} return "success ";}}
Summary
The above is a major update of spring-boot-klock-starter V1.1 main function introduced by Alibaba Cloud. I hope it will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!