- 授权协议: Apache
- 开发语言: Java
- 操作系统: 跨平台
- 软件首页: https://gitee.com/kekingcn/spring-boot-klock-starter
- 软件文档: https://gitee.com/kekingcn/spring-boot-klock-starter
软件介绍
spring-boot-klock-starter
基于redis的spring boot分布式锁组件,有了这个组件,使得项目拥有分布式锁能力变得异常简单,支持spring boot,和spirng mvc等spring相关项目。
快速开始
spring boot项目接入
1.添加lock starter组件依赖,目前还没上传到公共仓库,需要自己下源码build
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-klock-starter</artifactId> <version>1.0-SNAPSHOT</version> </dependency>
2.application.properties配置redis链接:spring.klock.address=127.0.0.1:6379
3.在需要加分布式锁的方法上,添加注解@Klock,如:
@Service
public class TestService {
@Klock(waitTime = Long.MAX_VALUE)
public String getValue(String param) throws Exception {
if ("sleep".equals(param)) {//线程休眠或者断点阻塞,达到一直占用锁的测试效果
Thread.sleep(1000 * 50);
}
return "success";
}
}spring mvc项目接入
其他步骤和spring boot步骤一样,只需要spring-xx.xml配置中添加KlockAutoConfiguration类扫描即可,如:
<context:component-scan base-package="org.springframework.boot.autoconfigure.klock.KlockAutoConfiguration"/>
使用参数说明
配置参数说明
spring.klock.address : redis链接地址 spring.klock.password :redis密码 spring.klock.database :redis数据索引 spring.klock.waitTime :获取锁最长阻塞时间(默认:60,单位:秒) spring.klock.leaseTime:已获取锁后自动释放时间(默认:60,单位:秒)
@Klock注解参数说明
@Klock可以标注四个参数,作用分别如下 name:lock的name,对应redis的key值。默认为:类名+方法名 lockType:锁的类型,目前支持(可重入锁,公平锁,读写锁)。默认为:公平锁 waitTime:获取锁最长等待时间。默认为:60s。同时也可通过spring.klock.waitTime统一配置 leaseTime:获得锁后,自动释放锁的时间。默认为:60s。同时也可通过spring.klock.leaseTime统一配置
关于测试
工程test模块下,为分布式锁的测试模块。可以快速体验分布式锁的效果。
Operating System Algorithms
Nathan Adams、Elisha Chirchir / CreateSpace Independent Publishing Platform / 2017-4-21 / USD 39.15
Operating System Algorithms will walk you through in depth examples of algorithms that you would find in an operating system. Selected algorithms include process and disk scheduling.一起来看看 《Operating System Algorithms》 这本书的介绍吧!
