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
ConstructorsConstructorDescriptionRedissonMultiLock(RLock... locks) Creates instance with multipleRLockobjects. -
Method Summary
Modifier and TypeMethodDescriptionprotected longcalcLockWaitTime(long remainTime) protected intbooleanUnlocks the lock independently of its stateUnlocks the lock independently of its stateintNumber of holds on this lock by the current threadNumber of holds on this lock by the current threadgetName()Returns name of objectbooleanChecks if this lock is held by the current threadbooleanisHeldByThread(long threadId) Checks if the lock is held by thread with definedthreadIdbooleanisLocked()Checks if the lock locked by any threadChecks if the lock locked by any threadvoidlock()voidAcquires 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 definedleaseTimeandthreadId.voidvoidlockInterruptibly(long leaseTime, TimeUnit unit) Acquires the lock with definedleaseTime.longRemaining time to live of the lockRemaining time to live of the lockbooleantryLock()booleanTries to acquire the lock with definedleaseTime.booleanTries 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 specifiedthreadIdandleaseTime.tryLockAsync(long waitTime, TimeUnit unit) Tries to acquire the lock.protected CompletionStage<Void> tryLockAsyncCycle(long threadId, long leaseTime, TimeUnit unit, long waitTime) voidunlock()Unlocks the lockunlockAsync(long threadId) Unlocks the lock.protected voidunlockInner(Collection<RLock> locks) unlockInnerAsync(Collection<RLock> locks, long threadId)
-
Constructor Details
-
RedissonMultiLock
Creates instance with multipleRLockobjects. 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:RLockAcquires the lock with definedleaseTime. Waits if necessary until lock became available. Lock will be released automatically after definedleaseTimeinterval. -
lockAsync
Description copied from interface:RLockAsyncAcquires the lock with definedleaseTime. Waits if necessary until lock became available. Lock will be released automatically after definedleaseTimeinterval.- Specified by:
lockAsyncin 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:RLockAsyncAcquires the lock with definedleaseTimeandthreadId. Waits if necessary until lock became available. Lock will be released automatically after definedleaseTimeinterval.- Specified by:
lockAsyncin 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:
lockInterruptiblyin interfaceLock- Throws:
InterruptedException
-
lockInterruptibly
Description copied from interface:RLockAcquires the lock with definedleaseTime. Waits if necessary until lock became available. Lock will be released automatically after definedleaseTimeinterval.- Specified by:
lockInterruptiblyin 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:
tryLockin interfaceLock- Throws:
InterruptedException
-
failedLocksLimit
protected int failedLocksLimit() -
tryLock
Description copied from interface:RLockTries to acquire the lock with definedleaseTime. Waits up to definedwaitTimeif necessary until the lock became available. Lock will be released automatically after definedleaseTimeinterval.- Specified by:
tryLockin interfaceRLock- Parameters:
waitTime- the maximum time to acquire the lockleaseTime- lease timeunit- time unit- Returns:
trueif lock is successfully acquired, otherwisefalseif lock is already set.- Throws:
InterruptedException- - if the thread is interrupted
-
tryLockAsync
Description copied from interface:RLockAsyncTries to acquire the lock by thread with specifiedthreadIdandleaseTime. Waits up to definedwaitTimeif necessary until the lock became available. Lock will be released automatically after definedleaseTimeinterval.- Specified by:
tryLockAsyncin interfaceRLockAsync- Parameters:
waitTime- time interval to acquire lockleaseTime- time interval after which lock will be released automaticallyunit- the time unit of thewaitTimeandleaseTimeargumentsthreadId- id of thread- Returns:
trueif lock acquired otherwisefalse
-
tryLockAsync
Description copied from interface:RLockAsyncTries to acquire the lock with definedleaseTime. Waits up to definedwaitTimeif necessary until the lock became available. Lock will be released automatically after definedleaseTimeinterval.- Specified by:
tryLockAsyncin interfaceRLockAsync- Parameters:
waitTime- the maximum time to acquire the lockleaseTime- lease timeunit- time unit- Returns:
trueif lock is successfully acquired, otherwisefalseif lock is already set.
-
calcLockWaitTime
protected long calcLockWaitTime(long remainTime) -
unlockAsync
Description copied from interface:RLockAsyncUnlocks the lock. ThrowsIllegalMonitorStateExceptionif lock isn't locked by thread with specifiedthreadId.- Specified by:
unlockAsyncin interfaceRLockAsync- Parameters:
threadId- id of thread- Returns:
- void
-
unlock
public void unlock() -
newCondition
- Specified by:
newConditionin interfaceLock
-
forceUnlockAsync
Description copied from interface:RLockAsyncUnlocks the lock independently of its state- Specified by:
forceUnlockAsyncin interfaceRLockAsync- Returns:
trueif lock existed and now unlocked otherwisefalse
-
unlockAsync
Description copied from interface:RLockAsyncUnlocks the lock- Specified by:
unlockAsyncin interfaceRLockAsync- Returns:
- void
-
tryLockAsync
Description copied from interface:RLockAsyncTries to acquire the lock.- Specified by:
tryLockAsyncin interfaceRLockAsync- Returns:
trueif lock acquired otherwisefalse
-
lockAsync
Description copied from interface:RLockAsyncAcquires the lock. Waits if necessary until lock became available.- Specified by:
lockAsyncin interfaceRLockAsync- Returns:
- void
-
lockAsync
Description copied from interface:RLockAsyncAcquires the lock by thread with definedthreadId. Waits if necessary until lock became available.- Specified by:
lockAsyncin interfaceRLockAsync- Parameters:
threadId- id of thread- Returns:
- void
-
tryLockAsync
Description copied from interface:RLockAsyncTries to acquire the lock by thread with specifiedthreadId.- Specified by:
tryLockAsyncin interfaceRLockAsync- Parameters:
threadId- id of thread- Returns:
trueif lock acquired otherwisefalse
-
tryLockAsync
Description copied from interface:RLockAsyncTries to acquire the lock. Waits up to definedwaitTimeif necessary until the lock became available.- Specified by:
tryLockAsyncin interfaceRLockAsync- Parameters:
waitTime- the maximum time to acquire the lockunit- time unit- Returns:
trueif lock is successfully acquired, otherwisefalseif lock is already set.
-
getHoldCountAsync
Description copied from interface:RLockAsyncNumber of holds on this lock by the current thread- Specified by:
getHoldCountAsyncin interfaceRLockAsync- Returns:
- holds or
0if this lock is not held by current thread
-
getName
Description copied from interface:RLockReturns name of object -
forceUnlock
public boolean forceUnlock()Description copied from interface:RLockUnlocks the lock independently of its state- Specified by:
forceUnlockin interfaceRLock- Returns:
trueif lock existed and now unlocked otherwisefalse
-
isLocked
public boolean isLocked()Description copied from interface:RLockChecks if the lock locked by any thread -
isLockedAsync
Description copied from interface:RLockAsyncChecks if the lock locked by any thread- Specified by:
isLockedAsyncin interfaceRLockAsync- Returns:
trueif locked otherwisefalse
-
isHeldByThread
public boolean isHeldByThread(long threadId) Description copied from interface:RLockChecks if the lock is held by thread with definedthreadId- Specified by:
isHeldByThreadin interfaceRLock- Parameters:
threadId- Thread ID of locking thread- Returns:
trueif held by thread with given id otherwisefalse
-
isHeldByCurrentThread
public boolean isHeldByCurrentThread()Description copied from interface:RLockChecks if this lock is held by the current thread- Specified by:
isHeldByCurrentThreadin interfaceRLock- Returns:
trueif held by current thread otherwisefalse
-
getHoldCount
public int getHoldCount()Description copied from interface:RLockNumber of holds on this lock by the current thread- Specified by:
getHoldCountin interfaceRLock- Returns:
- holds or
0if this lock is not held by current thread
-
remainTimeToLiveAsync
Description copied from interface:RLockAsyncRemaining time to live of the lock- Specified by:
remainTimeToLiveAsyncin 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:RLockRemaining time to live of the lock- Specified by:
remainTimeToLivein interfaceRLock- Returns:
- time in milliseconds -2 if the lock does not exist. -1 if the lock exists but has no associated expire.
-