Commit e9161d61 by 李乾广

优化锁等待

1 parent 2ab9c72a
...@@ -83,7 +83,7 @@ public class AuthInterceptor extends HandlerInterceptorAdapter { ...@@ -83,7 +83,7 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
String key = user.getUnid() + servletPath; String key = user.getUnid() + servletPath;
RLock lock = redissonClient.getLock("label:lock:" + key); RLock lock = redissonClient.getLock("label:lock:" + key);
try { try {
if (lock.tryLock(0, 10, TimeUnit.SECONDS)) { if (lock.tryLock(10, 10, TimeUnit.SECONDS)) {
//查看用户是否已经被锁定 //查看用户是否已经被锁定
SForbiddenUser param = new SForbiddenUser(); SForbiddenUser param = new SForbiddenUser();
param.setUserId(user.getUnid()); param.setUserId(user.getUnid());
...@@ -124,7 +124,11 @@ public class AuthInterceptor extends HandlerInterceptorAdapter { ...@@ -124,7 +124,11 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("你违规请求,我们已经记住你,请注意!"); throw new RuntimeException("你违规请求,我们已经记住你,请注意!");
} finally { } finally {
lock.unlock(); if (lock.isLocked()) {
if (lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
} }
return true; return true;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!