Package org.redisson.api
Interface RLock
- All Superinterfaces:
Lock
,RLockAsync
- All Known Subinterfaces:
RFencedLock
- All Known Implementing Classes:
RedissonBaseLock
,RedissonFairLock
,RedissonFencedLock
,RedissonLock
,RedissonMultiLock
,RedissonReadLock
,RedissonRedLock
,RedissonSpinLock
,RedissonTransactionalLock
,RedissonTransactionalReadLock
,RedissonTransactionalWriteLock
,RedissonWriteLock
Redis based implementation of
Lock
Implements re-entrant lock.- Author:
- Nikita Koksharov
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Unlocks the lock independently of its stateint
Number 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 threadvoid
Acquires the lock with definedleaseTime
.void
lockInterruptibly
(long leaseTime, TimeUnit unit) Acquires the lock with definedleaseTime
.long
Remaining time to live of the lockboolean
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, isHeldByThreadAsync, isLockedAsync, lockAsync, lockAsync, lockAsync, lockAsync, remainTimeToLiveAsync, tryLockAsync, tryLockAsync, tryLockAsync, tryLockAsync, tryLockAsync, unlockAsync, unlockAsync
-
Method Details
-
getName
String getName()Returns name of object- Returns:
- name - name of object
-
lockInterruptibly
Acquires the lock with definedleaseTime
. Waits if necessary until lock became available. Lock will be released automatically after definedleaseTime
interval.- 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
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.- 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
-
lock
Acquires the lock with definedleaseTime
. Waits if necessary until lock became available. Lock will be released automatically after definedleaseTime
interval.- 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:
true
if lock existed and now unlocked otherwisefalse
-
isLocked
boolean isLocked()Checks if the lock locked by any thread- Returns:
true
if 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:
true
if held by thread with given id otherwisefalse
-
isHeldByCurrentThread
boolean isHeldByCurrentThread()Checks if this lock is held by the current thread- Returns:
true
if held by current thread otherwisefalse
-
getHoldCount
int getHoldCount()Number of holds on this lock by the current thread- Returns:
- holds or
0
if 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.
-