Package org.redisson
Class RedissonMultiLock
java.lang.Object
org.redisson.RedissonMultiLock
- All Implemented Interfaces:
Lock
,RLock
,RLockAsync
- Direct Known Subclasses:
RedissonRedLock
Groups multiple independent locks and manages them as one lock.
- Author:
- Nikita Koksharov
-
Constructor Summary
ConstructorDescriptionRedissonMultiLock
(RLock... locks) Creates instance with multipleRLock
objects. -
Method Summary
Modifier and TypeMethodDescriptionprotected long
calcLockWaitTime
(long remainTime) protected int
boolean
Unlocks the lock independently of its stateUnlocks the lock independently of its stateint
Number of holds on this lock by the current threadNumber of holds on this lock by the current threadgetName()
Returns name of objectboolean
Checks if this lock is held by the current threadboolean
isHeldByThread
(long threadId) Checks if the lock is held by thread with definedthreadId
boolean
isLocked()
Checks if the lock locked by any threadChecks if the lock locked by any threadvoid
lock()
void
Acquires the lock with definedleaseTime
.Acquires the lock.lockAsync
(long threadId) Acquires the lock by thread with definedthreadId
.Acquires the lock with definedleaseTime
.Acquires the lock with definedleaseTime
andthreadId
.void
void
lockInterruptibly
(long leaseTime, TimeUnit unit) Acquires the lock with definedleaseTime
.long
Remaining time to live of the lockRemaining time to live of the lockboolean
tryLock()
boolean
Tries to acquire the lock with definedleaseTime
.boolean
Tries to acquire the lock.tryLockAsync
(long threadId) Tries to acquire the lock by thread with specifiedthreadId
.tryLockAsync
(long waitTime, long leaseTime, TimeUnit unit) Tries to acquire the lock with definedleaseTime
.tryLockAsync
(long waitTime, long leaseTime, TimeUnit unit, long threadId) Tries to acquire the lock by thread with specifiedthreadId
andleaseTime
.tryLockAsync
(long waitTime, TimeUnit unit) Tries to acquire the lock.protected CompletionStage<Void>
tryLockAsyncCycle
(long threadId, long leaseTime, TimeUnit unit, long waitTime) void
unlock()
Unlocks the lockunlockAsync
(long threadId) Unlocks the lock.protected void
unlockInner
(Collection<RLock> locks) unlockInnerAsync
(Collection<RLock> locks, long threadId)
-
Constructor Details
-
RedissonMultiLock
Creates instance with multipleRLock
objects. Each RLock object could be created by own Redisson instance.- Parameters:
locks
- - array of locks
-
-
Method Details
-
lock
public void lock() -
lock
Description copied from interface:RLock
Acquires the lock with definedleaseTime
. Waits if necessary until lock became available. Lock will be released automatically after definedleaseTime
interval. -
lockAsync
Description copied from interface:RLockAsync
Acquires the lock with definedleaseTime
. Waits if necessary until lock became available. Lock will be released automatically after definedleaseTime
interval.- Specified by:
lockAsync
in interfaceRLockAsync
- Parameters:
leaseTime
- the maximum time to hold the lock after it's acquisition, if it hasn't already been released by invokingunlock
. If leaseTime is -1, hold the lock until explicitly unlocked.unit
- the time unit- Returns:
- void
-
lockAsync
Description copied from interface:RLockAsync
Acquires the lock with definedleaseTime
andthreadId
. Waits if necessary until lock became available. Lock will be released automatically after definedleaseTime
interval.- Specified by:
lockAsync
in interfaceRLockAsync
- Parameters:
leaseTime
- the maximum time to hold the lock after it's acquisition, if it hasn't already been released by invokingunlock
. If leaseTime is -1, hold the lock until explicitly unlocked.unit
- the time unitthreadId
- id of thread- Returns:
- void
-
tryLockAsyncCycle
protected CompletionStage<Void> tryLockAsyncCycle(long threadId, long leaseTime, TimeUnit unit, long waitTime) -
lockInterruptibly
- Specified by:
lockInterruptibly
in interfaceLock
- Throws:
InterruptedException
-
lockInterruptibly
Description copied from interface:RLock
Acquires the lock with definedleaseTime
. Waits if necessary until lock became available. Lock will be released automatically after definedleaseTime
interval.- Specified by:
lockInterruptibly
in interfaceRLock
- Parameters:
leaseTime
- the maximum time to hold the lock after it's acquisition, if it hasn't already been released by invokingunlock
. If leaseTime is -1, hold the lock until explicitly unlocked.unit
- the time unit- Throws:
InterruptedException
- - if the thread is interrupted
-
tryLock
public boolean tryLock() -
unlockInner
-
unlockInnerAsync
-
tryLock
- Specified by:
tryLock
in interfaceLock
- Throws:
InterruptedException
-
failedLocksLimit
protected int failedLocksLimit() -
tryLock
Description copied from interface:RLock
Tries to acquire the lock with definedleaseTime
. Waits up to definedwaitTime
if necessary until the lock became available. Lock will be released automatically after definedleaseTime
interval.- Specified by:
tryLock
in interfaceRLock
- Parameters:
waitTime
- the maximum time to acquire the lockleaseTime
- lease timeunit
- time unit- Returns:
true
if lock is successfully acquired, otherwisefalse
if lock is already set.- Throws:
InterruptedException
- - if the thread is interrupted
-
tryLockAsync
Description copied from interface:RLockAsync
Tries to acquire the lock by thread with specifiedthreadId
andleaseTime
. Waits up to definedwaitTime
if necessary until the lock became available. Lock will be released automatically after definedleaseTime
interval.- Specified by:
tryLockAsync
in interfaceRLockAsync
- Parameters:
waitTime
- time interval to acquire lockleaseTime
- time interval after which lock will be released automaticallyunit
- the time unit of thewaitTime
andleaseTime
argumentsthreadId
- id of thread- Returns:
true
if lock acquired otherwisefalse
-
tryLockAsync
Description copied from interface:RLockAsync
Tries to acquire the lock with definedleaseTime
. Waits up to definedwaitTime
if necessary until the lock became available. Lock will be released automatically after definedleaseTime
interval.- Specified by:
tryLockAsync
in interfaceRLockAsync
- Parameters:
waitTime
- the maximum time to acquire the lockleaseTime
- lease timeunit
- time unit- Returns:
true
if lock is successfully acquired, otherwisefalse
if lock is already set.
-
calcLockWaitTime
protected long calcLockWaitTime(long remainTime) -
unlockAsync
Description copied from interface:RLockAsync
Unlocks the lock. ThrowsIllegalMonitorStateException
if lock isn't locked by thread with specifiedthreadId
.- Specified by:
unlockAsync
in interfaceRLockAsync
- Parameters:
threadId
- id of thread- Returns:
- void
-
unlock
public void unlock() -
newCondition
- Specified by:
newCondition
in interfaceLock
-
forceUnlockAsync
Description copied from interface:RLockAsync
Unlocks the lock independently of its state- Specified by:
forceUnlockAsync
in interfaceRLockAsync
- Returns:
true
if lock existed and now unlocked otherwisefalse
-
unlockAsync
Description copied from interface:RLockAsync
Unlocks the lock- Specified by:
unlockAsync
in interfaceRLockAsync
- Returns:
- void
-
tryLockAsync
Description copied from interface:RLockAsync
Tries to acquire the lock.- Specified by:
tryLockAsync
in interfaceRLockAsync
- Returns:
true
if lock acquired otherwisefalse
-
lockAsync
Description copied from interface:RLockAsync
Acquires the lock. Waits if necessary until lock became available.- Specified by:
lockAsync
in interfaceRLockAsync
- Returns:
- void
-
lockAsync
Description copied from interface:RLockAsync
Acquires the lock by thread with definedthreadId
. Waits if necessary until lock became available.- Specified by:
lockAsync
in interfaceRLockAsync
- Parameters:
threadId
- id of thread- Returns:
- void
-
tryLockAsync
Description copied from interface:RLockAsync
Tries to acquire the lock by thread with specifiedthreadId
.- Specified by:
tryLockAsync
in interfaceRLockAsync
- Parameters:
threadId
- id of thread- Returns:
true
if lock acquired otherwisefalse
-
tryLockAsync
Description copied from interface:RLockAsync
Tries to acquire the lock. Waits up to definedwaitTime
if necessary until the lock became available.- Specified by:
tryLockAsync
in interfaceRLockAsync
- Parameters:
waitTime
- the maximum time to acquire the lockunit
- time unit- Returns:
true
if lock is successfully acquired, otherwisefalse
if lock is already set.
-
getHoldCountAsync
Description copied from interface:RLockAsync
Number of holds on this lock by the current thread- Specified by:
getHoldCountAsync
in interfaceRLockAsync
- Returns:
- holds or
0
if this lock is not held by current thread
-
getName
Description copied from interface:RLock
Returns name of object -
forceUnlock
public boolean forceUnlock()Description copied from interface:RLock
Unlocks the lock independently of its state- Specified by:
forceUnlock
in interfaceRLock
- Returns:
true
if lock existed and now unlocked otherwisefalse
-
isLocked
public boolean isLocked()Description copied from interface:RLock
Checks if the lock locked by any thread -
isLockedAsync
Description copied from interface:RLockAsync
Checks if the lock locked by any thread- Specified by:
isLockedAsync
in interfaceRLockAsync
- Returns:
true
if locked otherwisefalse
-
isHeldByThread
public boolean isHeldByThread(long threadId) Description copied from interface:RLock
Checks if the lock is held by thread with definedthreadId
- Specified by:
isHeldByThread
in interfaceRLock
- Parameters:
threadId
- Thread ID of locking thread- Returns:
true
if held by thread with given id otherwisefalse
-
isHeldByCurrentThread
public boolean isHeldByCurrentThread()Description copied from interface:RLock
Checks if this lock is held by the current thread- Specified by:
isHeldByCurrentThread
in interfaceRLock
- Returns:
true
if held by current thread otherwisefalse
-
getHoldCount
public int getHoldCount()Description copied from interface:RLock
Number of holds on this lock by the current thread- Specified by:
getHoldCount
in interfaceRLock
- Returns:
- holds or
0
if this lock is not held by current thread
-
remainTimeToLiveAsync
Description copied from interface:RLockAsync
Remaining time to live of the lock- Specified by:
remainTimeToLiveAsync
in interfaceRLockAsync
- Returns:
- time in milliseconds -2 if the lock does not exist. -1 if the lock exists but has no associated expire.
-
remainTimeToLive
public long remainTimeToLive()Description copied from interface:RLock
Remaining time to live of the lock- Specified by:
remainTimeToLive
in interfaceRLock
- Returns:
- time in milliseconds -2 if the lock does not exist. -1 if the lock exists but has no associated expire.
-