1.现在错误的用法:
RLock lock = redisson.getLock(String.format(LOCK_KEY, 2));
try {
if (lock.tryLock()) {
//处理
logger.info("aaaaaaaaaaaaaaaaaa");
} catch(Exception e) {
//处理异常
} finally {
if (lock.isLocked()) {
lock.unlock();
}
}
测试实例:
TwoThread.java
public class TwoThread implements Runnable {
private RedissonClient redisson;
public TwoThread(RedissonClient redisson) {
this.redisson = redisson;
}
private Logger logger = LogManager.getLogger(getClass());
private String REWARD_CARD_LOCK_KEY = "444:lock:%d";
public void run() {
RLock lock = redisson.getLock(String.format(REWARD_CARD_LOCK_KEY, 2));
logger.info("thread---{}, lock:{}",Thread.currentThread().getId(), lock);
try {
if (lock.tryLock())