赞
踩
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(); } } }
最后改成
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(); } } }
解锁时,加了lock.isHeldByCurrentThread(),它的意思是查询当前线程是否持有此锁定,如果还持有,则释放,如果未持有,则说明已被释放;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。