Redis实现分布式锁全局锁—Redis客户端Redisson中分布式锁RLock实现
@Autowired
RedissonClient redissonClient;
String lock_str="lock_uniickId_"+id; RLock lock = redissonClient.getLock(lock_str); if (lock.isLocked()) { throw new NadaException(100, lock_str+"系统繁忙,请稍后再试"); } try { lock.lock(); //你的业务代码 } catch (Exception e) { e.printStackTrace(); throw new NadaException(100, " 系统繁忙,请稍后再试"); } finally { if (lock != null && lock.isLocked()) { lock.unlock(); } }