Redis-based spring-boot distributed lock component makes it extremely simple to have distributed lock capabilities for projects and is ready for use out of the box.
This component also works for spring mvc projects.
This update content:
The specific usage methods are as follows:
Use scenario description:
This update mainly solves the scenario where if the value of the parameter is the same, the value of the parameter needs to be locked, and if the value of the parameter is different, the scene is released without locking;
Use out of the box
1. Add 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 redis link: spring.klock.address=127.0.0.1:6379
3. To the method that requires a distributed lock, add annotation @Klock, such as:
@Servicepublic class TestService { @Klock(waitTime = Long.MAX_VALUE) public String getValue(String param) throws Exception { if ("sleep".equals(param)) {//Thread sleeps or breakpoints block, achieving the test effect of always occupying the lock Thread.sleep(1000 * 50); } return "success"; }}Summarize
The above is the introduction of the major update content of spring-boot-klock-starter V1.1 main function introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!