提交 167d507c 编写于 作者: W wuqian30624

Avoid redisson fair lock blocking if there are lots of registered threads in queue but not used.

Signed-off-by: Nwuqian30624 <wuqian0808@me.com>
上级 24b49b01
......@@ -201,6 +201,22 @@ 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]);" +
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册