diff --git a/mes/hd/nladmin-system/pom.xml b/mes/hd/nladmin-system/pom.xml index ffa3807e..08daa37b 100644 --- a/mes/hd/nladmin-system/pom.xml +++ b/mes/hd/nladmin-system/pom.xml @@ -33,6 +33,12 @@ thumbnailator 0.4.8 + + org.redisson + redisson-spring-boot-starter + 3.12.3 + + e-iceblue diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/config/Democontroller.java b/mes/hd/nladmin-system/src/main/java/org/nl/config/Democontroller.java new file mode 100644 index 00000000..36f1e457 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/config/Democontroller.java @@ -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"; + } +} diff --git a/mes/hd/nladmin-system/src/main/resources/config/application-dev.yml b/mes/hd/nladmin-system/src/main/resources/config/application-dev.yml index c0c80be0..5b501a26 100644 --- a/mes/hd/nladmin-system/src/main/resources/config/application-dev.yml +++ b/mes/hd/nladmin-system/src/main/resources/config/application-dev.yml @@ -70,12 +70,30 @@ spring: multi-statement-allow: true redis: #数据库索引 - database: ${REDIS_DB:14} - host: ${REDIS_HOST:47.111.78.178} - port: ${REDIS_PORT:6379} - password: ${REDIS_PWD:} - #连接超时时间 - timeout: 5000 + database: 1 + # Redis服务器地址 + host: 47.96.133.178 + # Redis服务器连接端口 + port: 6479 + # Redis服务器连接密码(默认为空) + password: 942464Yy +redisson: + # redis key前缀 + keyPrefix: + # 线程池数量 + threads: 4 + # Netty线程池数量 + nettyThreads: 8 + # 单节点配置 + singleServerConfig: + # 最小空闲连接数 + connectionMinimumIdleSize: 8 + # 连接池大小 + connectionPoolSize: 32 + # 连接空闲超时,单位:毫秒 + idleConnectionTimeout: 10000 + # 命令等待超时,单位:毫秒 + timeout: 3000 # 登录相关配置 login: # 登录缓存 @@ -147,3 +165,4 @@ logging: file: path: C:\log\wms config: classpath:logback-spring.xml +