引入redisson
This commit is contained in:
@@ -33,6 +33,12 @@
|
|||||||
<artifactId>thumbnailator</artifactId>
|
<artifactId>thumbnailator</artifactId>
|
||||||
<version>0.4.8</version>
|
<version>0.4.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.redisson</groupId>
|
||||||
|
<artifactId>redisson-spring-boot-starter</artifactId>
|
||||||
|
<version>3.12.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Excel打印-->
|
<!-- Excel打印-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>e-iceblue</groupId>
|
<groupId>e-iceblue</groupId>
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package org.nl.config;
|
||||||
|
|
||||||
|
import org.redisson.api.RLock;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author ZZQ
|
||||||
|
* @Date 2022/12/15 4:39 下午
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/lockdemo")
|
||||||
|
public class Democontroller {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RedissonClient redisLock;
|
||||||
|
@RequestMapping("/1")
|
||||||
|
|
||||||
|
public String demo() throws Exception {
|
||||||
|
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
|
||||||
|
RLock lock = redisLock.getLock("wqlcode" + "falg1");
|
||||||
|
if (lock.tryLock(1000, TimeUnit.SECONDS)){
|
||||||
|
try {
|
||||||
|
System.out.println(Thread.currentThread().getName()+"获取到锁");
|
||||||
|
Thread.sleep(3000);
|
||||||
|
} finally {
|
||||||
|
System.out.println("释放");
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
|
||||||
|
RLock lock = redisLock.getLock("wqlcode" + "falg1");
|
||||||
|
if (lock.tryLock(1000, TimeUnit.SECONDS)){
|
||||||
|
try {
|
||||||
|
System.out.println(Thread.currentThread().getName()+"获取到锁");
|
||||||
|
Thread.sleep(3000);
|
||||||
|
} finally {
|
||||||
|
System.out.println("释放");
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
|
||||||
|
return "sucess";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -70,12 +70,30 @@ spring:
|
|||||||
multi-statement-allow: true
|
multi-statement-allow: true
|
||||||
redis:
|
redis:
|
||||||
#数据库索引
|
#数据库索引
|
||||||
database: ${REDIS_DB:14}
|
database: 1
|
||||||
host: ${REDIS_HOST:47.111.78.178}
|
# Redis服务器地址
|
||||||
port: ${REDIS_PORT:6379}
|
host: 47.96.133.178
|
||||||
password: ${REDIS_PWD:}
|
# Redis服务器连接端口
|
||||||
#连接超时时间
|
port: 6479
|
||||||
timeout: 5000
|
# Redis服务器连接密码(默认为空)
|
||||||
|
password: 942464Yy
|
||||||
|
redisson:
|
||||||
|
# redis key前缀
|
||||||
|
keyPrefix:
|
||||||
|
# 线程池数量
|
||||||
|
threads: 4
|
||||||
|
# Netty线程池数量
|
||||||
|
nettyThreads: 8
|
||||||
|
# 单节点配置
|
||||||
|
singleServerConfig:
|
||||||
|
# 最小空闲连接数
|
||||||
|
connectionMinimumIdleSize: 8
|
||||||
|
# 连接池大小
|
||||||
|
connectionPoolSize: 32
|
||||||
|
# 连接空闲超时,单位:毫秒
|
||||||
|
idleConnectionTimeout: 10000
|
||||||
|
# 命令等待超时,单位:毫秒
|
||||||
|
timeout: 3000
|
||||||
# 登录相关配置
|
# 登录相关配置
|
||||||
login:
|
login:
|
||||||
# 登录缓存
|
# 登录缓存
|
||||||
@@ -147,3 +165,4 @@ logging:
|
|||||||
file:
|
file:
|
||||||
path: C:\log\wms
|
path: C:\log\wms
|
||||||
config: classpath:logback-spring.xml
|
config: classpath:logback-spring.xml
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user