当前位置:   article > 正文

attempt to unlock lock, not locked by current thread by node id: 83394267-6fff-450c-8cee-2690f845ec4_attempt to unlock lock,not locked by current

attempt to unlock lock,not locked by current

使用redis的分布式锁出现了下面的错误:

attempt to unlock lock, not locked by current thread by node id: 83394267-6fff-450c-8cee-2690f845ec4f thread-id: 89

有问题的代码:

  1. //从redis查不到,则走mysql
  2. String key = getLiveFaceResourceStLockKey(region);
  3. RLock rLock = redissonRedisService.getLock(key);
  4. try {
  5. log.info("live_face_resource_st_from_mysql_get_lock");
  6. boolean bool = rLock.tryLock(RedisKey.EXPIRE_TEN_SECONDS, TimeUnit.SECONDS);
  7. if (bool) {
  8. List<LiveFaceResourceSt> stList = liveFaceResourceStService.selectListOnline(region, platform);
  9. resourcesResponseList.addAll(ListUtils.emptyIfNull(stList).stream()
  10. .filter(Objects::nonNull)
  11. .map(this::convert)
  12. .collect(Collectors.toList()));
  13. if (CollectionUtils.isNotEmpty(resourcesResponseList)) {
  14. micoRedisService.string().set(getLiveFaceResourceStKey(region), JSON.toJSONString(resourcesResponseList));
  15. micoRedisService.expire(getLiveFaceResourceStKey(region), RedisKey.EXPIRE_FIVE_MINUTE, TimeUnit.SECONDS);
  16. }
  17. }
  18. } catch (Exception e) {
  19. log.error("live_face_resource_st_from_mysql_lock_fail:", e);
  20. } finally {
  21. if (rLock.isLocked()) {
  22. try {
  23. rLock.unlock();
  24. } catch (Exception e) {
  25. log.error("live_face_resource_st解锁异常:", e);
  26. }
  27. }
  28. }

修复后的代码:

  1. //从redis查不到,则走mysql
  2. String key = getLiveFaceResourceStLockKey(region, platform);
  3. RLock lock = redissonRedisService.getLock(key);
  4. lock.lock(10, TimeUnit.SECONDS);
  5. try {
  6. List<LiveFaceResourceSt> stList = liveFaceResourceStService.selectListOnline(region, platform);
  7. resourcesResponseList.addAll(ListUtils.emptyIfNull(stList).stream()
  8. .filter(Objects::nonNull)
  9. .map(this::convert)
  10. .collect(Collectors.toList()));
  11. if (CollectionUtils.isNotEmpty(resourcesResponseList)) {
  12. micoRedisService.string().set(getLiveFaceResourceStKey(region, platform), JSON.toJSONString(resourcesResponseList));
  13. micoRedisService.expire(getLiveFaceResourceStKey(region, platform), RedisKey.EXPIRE_FIVE_MINUTE, TimeUnit.SECONDS);
  14. }
  15. } catch (Exception e) {
  16. log.error("live_face_resource_st_from_mysql_lock_fail:", e);
  17. } finally {
  18. if (lock.isLocked()) {
  19. lock.unlock();
  20. }
  21. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/1009042
推荐阅读
相关标签
  

闽ICP备14008679号