Package org.redisson.api
Interface RLock
-
- All Superinterfaces:
Lock
,RExpirable
,RExpirableAsync
,RLockAsync
,RObject
,RObjectAsync
- All Known Implementing Classes:
RedissonFairLock
,RedissonLock
,RedissonReadLock
,RedissonTransactionalLock
,RedissonWriteLock
public interface RLock extends Lock, RExpirable, RLockAsync
Distributed implementation ofLock
Implements reentrant lock. UsegetHoldCount()
to get a holds count.- Author:
- Nikita Koksharov
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
forceUnlock()
Unlocks lock independently of stateint
getHoldCount()
Number of holds on this lock by the current threadboolean
isHeldByCurrentThread()
Checks if this lock is held by the current threadboolean
isLocked()
Checks if this lock locked by any threadvoid
lock(long leaseTime, TimeUnit unit)
Acquires the lock.void
lockInterruptibly(long leaseTime, TimeUnit unit)
Acquires the lock.boolean
tryLock(long waitTime, long leaseTime, TimeUnit unit)
Returnstrue
as soon as the lock is acquired.-
Methods inherited from interface java.util.concurrent.locks.Lock
lock, lockInterruptibly, newCondition, tryLock, tryLock, unlock
-
Methods inherited from interface org.redisson.api.RExpirable
clearExpire, expire, expireAt, expireAt, remainTimeToLive
-
Methods inherited from interface org.redisson.api.RExpirableAsync
clearExpireAsync, expireAsync, expireAtAsync, expireAtAsync, remainTimeToLiveAsync
-
Methods inherited from interface org.redisson.api.RLockAsync
forceUnlockAsync, getHoldCountAsync, lockAsync, lockAsync, lockAsync, lockAsync, tryLockAsync, tryLockAsync, tryLockAsync, tryLockAsync, tryLockAsync, unlockAsync, unlockAsync
-
Methods inherited from interface org.redisson.api.RObject
copy, delete, dump, getCodec, getName, isExists, migrate, move, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlink
-
Methods inherited from interface org.redisson.api.RObjectAsync
copyAsync, deleteAsync, dumpAsync, isExistsAsync, migrateAsync, moveAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsync
-
-
-
-
Method Detail
-
lockInterruptibly
void lockInterruptibly(long leaseTime, TimeUnit unit) throws InterruptedException
Acquires the lock.If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired. If the lock is acquired, it is held until
unlock
is invoked, or until leaseTime have passed since the lock was granted - whichever comes first.- Parameters:
leaseTime
- the maximum time to hold the lock after granting it, before automatically releasing it if it hasn't already been released by invokingunlock
. If leaseTime is -1, hold the lock until explicitly unlocked.unit
- the time unit of theleaseTime
argument- Throws:
InterruptedException
- - if the thread is interrupted before or during this method.
-
tryLock
boolean tryLock(long waitTime, long leaseTime, TimeUnit unit) throws InterruptedException
Returnstrue
as soon as the lock is acquired. If the lock is currently held by another thread in this or any other process in the distributed system this method keeps trying to acquire the lock for up towaitTime
before giving up and returningfalse
. If the lock is acquired, it is held untilunlock
is invoked, or untilleaseTime
have passed since the lock was granted - whichever comes first.- Parameters:
waitTime
- the maximum time to aquire the lockleaseTime
- lease timeunit
- time unit- Returns:
true
if lock has been successfully acquired- Throws:
InterruptedException
- - if the thread is interrupted before or during this method.
-
lock
void lock(long leaseTime, TimeUnit unit)
Acquires the lock.If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired. If the lock is acquired, it is held until
unlock
is invoked, or until leaseTime milliseconds have passed since the lock was granted - whichever comes first.- Parameters:
leaseTime
- the maximum time to hold the lock after granting it, before automatically releasing it if it hasn't already been released by invokingunlock
. If leaseTime is -1, hold the lock until explicitly unlocked.unit
- the time unit of theleaseTime
argument
-
forceUnlock
boolean forceUnlock()
Unlocks lock independently of state- Returns:
true
if unlocked otherwisefalse
-
isLocked
boolean isLocked()
Checks if this lock locked by any thread- Returns:
true
if locked 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
-
-