diff --git a/redisson/src/main/java/org/redisson/RedissonFairLock.java b/redisson/src/main/java/org/redisson/RedissonFairLock.java index b6f973efcd6c8ba82573ca7315d05a951c3791ea..fa807774652544fe742959e8e2ed684514407943 100644 --- a/redisson/src/main/java/org/redisson/RedissonFairLock.java +++ b/redisson/src/main/java/org/redisson/RedissonFairLock.java @@ -201,22 +201,6 @@ public class RedissonFairLock extends RedissonLock implements RLock { "return nil;" + "end;" + - - // check if the lock is not held, and other queues are not used - "while true do " + - "local firstThreadId = redis.call('lindex', KEYS[2], 0);" + - "if (firstThreadId == false) or (firstThreadId == ARGV[2]) then " + - "break;"+ - "end;" + - "local timeout = tonumber(redis.call('zscore', KEYS[3], firstThreadId));" + - "if (timeout > tonumber(ARGV[4])) and (redis.call('exists', KEYS[1]) == 0) then " + - "redis.call('lpop', KEYS[2]);" + - "redis.call('zrem', KEYS[3], firstThreadId);" + - "else " + - "break;" + - "end;" + - "end;" + - // the lock cannot be acquired // check if the thread is already in the queue "local timeout = redis.call('zscore', KEYS[3], ARGV[2]);" + diff --git a/redisson/src/test/java/org/redisson/RedissonFairLockTest.java b/redisson/src/test/java/org/redisson/RedissonFairLockTest.java index 96a7e966190cb068b40dc55e03641f2d2c9815bc..922ee84d72edff6272346139df0e80f683a509fe 100644 --- a/redisson/src/test/java/org/redisson/RedissonFairLockTest.java +++ b/redisson/src/test/java/org/redisson/RedissonFairLockTest.java @@ -933,62 +933,5 @@ public class RedissonFairLockTest extends BaseConcurrentTest { await().atMost(30, TimeUnit.SECONDS).until(() -> lockedCounter.get() == totalThreads); } - @Test - public void testLockBlock() throws InterruptedException{ - Config cfg = createConfig(); - cfg.setLockWatchdogTimeout(30000); - RedissonClient redisson = Redisson.create(cfg); - int totalExecutorCount = 5; - int totalThreadCount = 100; - int interval = 1000; - Lock lock = redisson.getFairLock("testLockBlock"); - for (int count = 0; count < totalExecutorCount; count++) { - ExecutorService executor = Executors.newFixedThreadPool(totalThreadCount); - for (int i = 0; i < totalThreadCount; i++) { - final int finalI = i; - executor.submit(() -> { - log.info("running " + finalI + " in thread " + Thread.currentThread().getId()); - try { - lock.lock(); - log.info("Thread " + finalI + " got lock"); - } catch (Exception ex) { - log.error("Failed to get lock"); - } finally { - lock.unlock(); - } - }); - } - executor.shutdownNow(); - } - redisson.shutdown(); - - // In case connection closed - redisson = Redisson.create(cfg); - long timeOut = redisson.getConfig().getLockWatchdogTimeout() + interval; - ExecutorService lockExecutor = Executors.newFixedThreadPool(1); - Lock lockSecond = redisson.getFairLock("testLockBlock"); - Future future = lockExecutor.submit(new Callable() { - @Override - public Boolean call() throws Exception { - // check if this lock can be acquired in short time - Thread.sleep(timeOut); - lockSecond.lock(); - return Boolean.TRUE; - } - }); - - Boolean got = Boolean.FALSE; - try{ - got = future.get(timeOut + interval, TimeUnit.MILLISECONDS); - if (got) { - log.info("Got lock immediately after startup"); - }else{ - log.info("Failed to get lock due to blocked"); - } - }catch (Exception e){ - log.info("Failed to get lock due to blocked"); - } - Assert.assertTrue(got); - } }