当前位置:   article > 正文

attempt to unlock lock, not locked by current thread by node id

attempt to unlock lock, not locked by current thread by node id:

attempt to unlock lock, not locked by current thread by node id: ee1333c7-c195-4d3a-80af-f39f3f8e17df thread-id: 69
当时的代码是这样写的

public void execute() {
        String timerName = HandJob.class.getName()
                + Thread.currentThread().getStackTrace()[1].getMethodName();
        RLock lock = redissonClient.getLock(RedisConstant.REDIS_PREFIX + timerName);
        boolean tryLock = lock.tryLock();
        try{
            if(tryLock){
               this.handleSign();
            }else{
                log.info("HandJob.execute 未获取到锁"+lock.getName());
            }
        }catch (Exception exception){
            log.error("HandJob.execute",exception);
        }finally {
            if (lock.isLocked()) {
                lock.unlock();
            }
        }

    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

最后改成

    public void execute() {
        String timerName = Hand.class.getName()
                + Thread.currentThread().getStackTrace()[1].getMethodName();
        RLock lock = redissonClient.getLock(RedisConstant.REDIS_PREFIX + timerName);
        boolean tryLock = lock.tryLock();
        try{
            if(tryLock){
               this.handleSign();
            }else{
                log.info("HandJob.execute 未获取到锁"+lock.getName());
            }
        }catch (Exception exception){
            log.error("Hand.execute",exception);
        }finally {
            if (lock.isLocked() && lock.isHeldByCurrentThread()) {
                lock.unlock();
            }
        }


    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

解锁时,加了lock.isHeldByCurrentThread(),它的意思是查询当前线程是否持有此锁定,如果还持有,则释放,如果未持有,则说明已被释放;

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号