Package org.redisson.api
Interface RLock
-
- All Superinterfaces:
Lock,RLockAsync
- All Known Implementing Classes:
RedissonBaseLock,RedissonFairLock,RedissonLock,RedissonMultiLock,RedissonReadLock,RedissonRedLock,RedissonSpinLock,RedissonTransactionalLock,RedissonWriteLock
public interface RLock extends Lock, RLockAsync
Redis based implementation ofLockImplements re-entrant lock.- Author:
- Nikita Koksharov
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanforceUnlock()Unlocks the lock independently of its stateintgetHoldCount()Number of holds on this lock by the current threadStringgetName()Returns name of objectbooleanisHeldByCurrentThread()Checks 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 threadvoidlock(long leaseTime, TimeUnit unit)Acquires the lock with definedleaseTime.voidlockInterruptibly(long leaseTime, TimeUnit unit)Acquires the lock with definedleaseTime.longremainTimeToLive()Remaining time to live of the lockbooleantryLock(long waitTime, long leaseTime, TimeUnit unit)Tries to acquire the lock with definedleaseTime.-
Methods inherited from interface java.util.concurrent.locks.Lock
lock, lockInterruptibly, newCondition, tryLock, tryLock, unlock
-
Methods inherited from interface org.redisson.api.RLockAsync
forceUnlockAsync, getHoldCountAsync, isLockedAsync, lockAsync, lockAsync, lockAsync, lockAsync, remainTimeToLiveAsync, tryLockAsync, tryLockAsync, tryLockAsync, tryLockAsync, tryLockAsync, unlockAsync, unlockAsync
-
-
-
-
Method Detail
-
getName
String getName()
Returns name of object- Returns:
- name - name of object
-
lockInterruptibly
void lockInterruptibly(long leaseTime, TimeUnit unit) throws InterruptedExceptionAcquires the lock with definedleaseTime. Waits if necessary until lock became available. Lock will be released automatically after definedleaseTimeinterval.- 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
boolean tryLock(long waitTime, long leaseTime, TimeUnit unit) throws InterruptedExceptionTries to acquire the lock with definedleaseTime. Waits up to definedwaitTimeif necessary until the lock became available. Lock will be released automatically after definedleaseTimeinterval.- 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
-
lock
void lock(long leaseTime, TimeUnit unit)Acquires the lock with definedleaseTime. Waits if necessary until lock became available. Lock will be released automatically after definedleaseTimeinterval.- 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
-
forceUnlock
boolean forceUnlock()
Unlocks the lock independently of its state- Returns:
trueif lock existed and now unlocked otherwisefalse
-
isLocked
boolean isLocked()
Checks if the lock locked by any thread- Returns:
trueif locked otherwisefalse
-
isHeldByThread
boolean isHeldByThread(long threadId)
Checks if the lock is held by thread with definedthreadId- Parameters:
threadId- Thread ID of locking thread- Returns:
trueif held by thread with given id otherwisefalse
-
isHeldByCurrentThread
boolean isHeldByCurrentThread()
Checks if this lock is held by the current thread- Returns:
trueif held by current thread otherwisefalse
-
getHoldCount
int getHoldCount()
Number of holds on this lock by the current thread- Returns:
- holds or
0if this lock is not held by current thread
-
remainTimeToLive
long remainTimeToLive()
Remaining time to live of the lock- Returns:
- time in milliseconds -2 if the lock does not exist. -1 if the lock exists but has no associated expire.
-
-