锁修改
This commit is contained in:
@@ -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){
|
||||||
|
|||||||
Reference in New Issue
Block a user