锁修改

This commit is contained in:
2024-09-28 16:09:04 +08:00
parent e0b2088087
commit 07f31ebf50

View File

@@ -49,14 +49,14 @@ public class Utils {
// 创建线程id, 用作判断 // 创建线程id, 用作判断
String clientId = UUID.randomUUID().toString(); String clientId = UUID.randomUUID().toString();
// 设置分布式锁 // 设置分布式锁
boolean lock = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(lockKey, clientId, 30, TimeUnit.MILLISECONDS)); boolean lock = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(lockKey, clientId, 30, TimeUnit.SECONDS));
int count = 0; int count = 0;
while (!lock) { while (!lock) {
if (count++ > 100) { if (count++ > 100) {
throw new MsgException("系统繁忙, 稍后再试"); throw new MsgException("系统繁忙, 稍后再试");
} }
Thread.sleep(20); Thread.sleep(20);
lock = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(lockKey, clientId, 30, TimeUnit.MILLISECONDS)); lock = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(lockKey, clientId, 30, TimeUnit.SECONDS));
} }
return supplier.get(); return supplier.get();
} catch (RuntimeException e){ } catch (RuntimeException e){