123备份



        String alock = deviceStatusSyncParam.getSn();
        APIResult res = new APIResult();
        RLock lock = redissonClient.getLock(alock);
        boolean getLock = false;
        try {
            if (getLock = lock.tryLock(120, TimeUnit.SECONDS)) {
                logger.info("start time:" + DateUtils.format(new Date()));
                logger.info("Redisson获取到分布式锁:{},ThreadName:{}", alock, Thread.currentThread().getName());

                String redisCompanyCode = Optional.ofNullable(stringRedisTemplate.opsForHash().get(RedisKey.getDeviceInfo(deviceStatusSyncParam.getSn()), RedisKey.DeviceField.companyCode.name()))
                        .map(Object::toString).orElse(StringUtils.EMPTY);
                logger.info("[companyCode] io同步的公司编码:" + deviceStatusSyncParam.getCompanyCode());
                logger.info("[redisCompanyCode] redis的公司编码:" + deviceStatusSyncParam.getCompanyCode());
                logger.info("[syncStatus] io同步的状态:" + syncStatus);
                if (!(!deviceStatusSyncParam.getCompanyCode().equals(redisCompanyCode) && syncStatus.equals(-1))) {
                    logger.info("执行device缓存的更新操作");
                    this.cache(Collections.singletonList(device), CurdEnum.UPDATE, deviceStatusSyncParam.getCompanyCode());
                }
                Thread.sleep(60000);
                System.out.println("sleeping ...  ");
                logger.info("end time:" + DateUtils.format(new Date()));
            } else {
                logger.info("Redisson没有获取到分布式锁:{},ThreadName:{}", alock, Thread.currentThread().getName());
            }
        } catch (InterruptedException e) {
            logger.error("Redisson分布式锁获取异常", e);
        } finally {
            if (!getLock) {
                return;
            }
            lock.unlock();
            logger.info("Redisson分布式锁释放锁");
        }
    }



            org.redisson
            redisson-spring-boot-starter
            3.10.7
            
                
                    org.redisson
                    redisson-spring-data-21
                
            
        
        
            org.redisson
            redisson-spring-data-20
            3.10.7
        

你可能感兴趣的:(123备份)