Browse Source

lock 指定线程

yegang 2 years ago
parent
commit
245cf6539e
1 changed files with 5 additions and 1 deletions
  1. 5 1
      src/main/java/com/sw/service/impl/SnatchMaskServiceImpl.java

+ 5 - 1
src/main/java/com/sw/service/impl/SnatchMaskServiceImpl.java

@@ -165,7 +165,11 @@ public class SnatchMaskServiceImpl implements SnatchMaskService {
                 log.info("线程:{} 获取锁", threadName);
                 Thread.sleep(3000);
                 log.info("doSnatch方法执行结果:{}", this.doSnatch(uid, maskId));
-                lock.unlock();
+                if (lock.isLocked()) {
+                    if (lock.isHeldByCurrentThread()) {
+                        lock.unlock();
+                    }
+                }
                 log.info("{}:业务执行完成", threadName);
                 break;
             }