public interface Lock
| Modifier and Type | Method and Description |
|---|---|
long |
epoch()
Returns the epoch for this lock.
|
boolean |
extendExpiration(int leaseDurationMillis)
Extends the expiration time for a lock that is currently owned
by a specified duration.
|
boolean |
isLocked()
Returns true if this Lock instance currently holds the lock.
|
void |
lock(int leaseDurationMillis)
Acquires the lock.
|
CompletableFuture<Void> |
lockAsync(int leaseDurationMillis)
Acquires the lock asynchronously.
|
String |
path()
Returns the path this lock will be used to guard from concurrent access.
|
boolean |
tryLock(int leaseDurationMillis)
Acquires the lock only if it is free at the time of invocation.
|
boolean |
tryLock(int waitTimeMillis,
int leaseDurationMillis)
Acquires the lock if it is free within the given waiting
time and the current thread has not been interrupted.
|
void |
unlock()
Releases the lock.
|
String path()
void lock(int leaseDurationMillis) throws InterruptedException
Locks are reentrant. A thread invoking this method multiple times without an intervening unlock or lease expiration must invoke unlock() the same number of times before the lock is released (unless the lease expires). When this method is invoked for a lock that is already acquired, the lease time will be set to the maximum of the remaining lease time from the previous invocation, or leaseDurationMillis.
leaseDurationMillis - the number of milliseconds to hold the
lock after granting it, before automatically releasing it if it hasn't
already been released by invoking unlock(). Must be in the range
(0, LockManager.MAX_LEASE_MILLIS]InterruptedException - if the thread is interrupted while waitingCompletableFuture<Void> lockAsync(int leaseDurationMillis)
leaseDurationMillis - leaseDurationMillis the number of milliseconds the lock
will be reserved before it becomes available for others.boolean tryLock(int leaseDurationMillis)
leaseDurationMillis - the number of milliseconds the must be
locked after it is granted, before automatically releasing it if it hasn't
already been released by an invocation of unlock(). Must be in the range
(0, LockManager.MAX_LEASE_MILLIS]boolean tryLock(int waitTimeMillis,
int leaseDurationMillis)
throws InterruptedException
waitTimeMillis - the maximum time (in milliseconds) to wait for the lockleaseDurationMillis - the number of milliseconds to hold the
lock after granting it, before automatically releasing it if it hasn't
already been released by invoking unlock(Object). Must be in the range
(0, LockManager.MAX_LEASE_MILLIS]InterruptedException - if the thread is interrupted while waitingboolean isLocked()
long epoch()
void unlock()
boolean extendExpiration(int leaseDurationMillis)
leaseDurationMillis - extension duration.Copyright © 2015. All rights reserved.