DistributedLock icon indicating copy to clipboard operation
DistributedLock copied to clipboard

Distributed Lock programmed in Java

Results 2 DistributedLock issues
Sort by recently updated
recently updated
newest added

if (isTimeExpired(currLockInfo.getExpires())) { // 锁超时了 LockInfo oldLockInfo = LockInfo.fromString(jedis.getSet(lockKey, newLockInfoJson)); //,这里需要判断redis所内容是否为当前锁,要不然并发情况会被多个线程获得锁 //String newSetLockInfoJson = redisTemplate.opsForValue().get(lockKey); //if (oldLockInfo != null && isTimeExpired(oldLockInfo.getExpires()) && //newSetLockInfoJson.equals(newLockInfoJson)) { if (oldLockInfo != null && isTimeExpired(oldLockInfo.getExpires()))...

`if (isTimeExpired(currLockInfo.getExpires())) ` 运行过程中异常中断,redis中会有一条锁记录,当程序重新启动后,多个线程会争抢锁,导致锁异常。 ``` LockInfo currLockInfo = LockInfo.fromString(currLockInfoJson); // 竞争条件只可能出现在锁超时的情况, 因为如果没有超时, 线程发现锁并不是被自己持有, 线程就不会去动value if (isTimeExpired(currLockInfo.getExpires())) { // 锁超时了 LockInfo oldLockInfo = LockInfo.fromString(jedis.getSet(lockKey, newLockInfoJson)); if (oldLockInfo != null && isTimeExpired(oldLockInfo.getExpires()))...