赞
踩
在前段设置状态在响应时进入遮罩层或给按钮一个状态
- //获取setNX锁
- if (redisTemplate.opsForValue().setIfAbsent("lock", orderId)) {
- //获取锁成功
- try {
- //Redission 获取锁
- RLock lock = redissonClient.getLock("lock");
- boolean acquired = lock.tryLock(10, TimeUnit.SECONDS); // 尝试获取锁,最多等待10秒
- if (acquired) {
- try {
- // 执行业务逻辑
-
- } finally {
- lock.unlock(); // 记得解锁
- }
- }
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- } finally {
- //删除锁
- redisTemplate.delete("lock");
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。