瀏覽代碼

lock 指定线程

yegang 2 年之前
父節點
當前提交
245cf6539e
共有 1 個文件被更改,包括 5 次插入1 次删除
  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;
             }