public interface ILock extends Lock, DistributedObject
Lock
.
Lock mylock = Hazelcast.getLock(mylockobject); mylock.lock();
try {
// do something
} finally {
mylock.unlock();
}
//Lock on Map
IMap map = Hazelcast.getMap("customers"); map.lock("1");
try {
// do something
} finally {
map.unlock("1"); }
Lock
Modifier and Type | Method and Description |
---|---|
void |
forceUnlock()
Releases the lock regardless of the lock owner.
|
Object |
getKey()
Deprecated.
use
DistributedObject.getName() instead. |
int |
getLockCount()
Returns re-entrant lock hold count, regardless of lock ownership.
|
long |
getRemainingLeaseTime()
Returns remaining lease time in milliseconds.
|
boolean |
isLocked()
Returns whether this lock is locked or not.
|
boolean |
isLockedByCurrentThread()
Returns whether this lock is locked by current thread or not.
|
void |
lock() |
void |
lock(long leaseTime,
TimeUnit timeUnit)
Acquires the lock for the specified lease time.
|
Condition |
newCondition()
This method is not implemented! Use
newCondition(String) instead. |
ICondition |
newCondition(String name)
Returns a new
ICondition instance that is bound to this
ILock instance with given name. |
boolean |
tryLock() |
boolean |
tryLock(long time,
TimeUnit unit) |
boolean |
tryLock(long time,
TimeUnit unit,
long leaseTime,
TimeUnit leaseUnit)
Tries to acquire the lock for the specified lease time.
|
void |
unlock()
Releases the lock.
|
lockInterruptibly
destroy, getName, getPartitionKey, getServiceName
@Deprecated Object getKey()
DistributedObject.getName()
instead.boolean tryLock(long time, TimeUnit unit) throws InterruptedException
tryLock
in interface Lock
InterruptedException
boolean tryLock(long time, TimeUnit unit, long leaseTime, TimeUnit leaseUnit) throws InterruptedException
After lease time, the lock will be released.
If the lock is not available, then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:
time
- maximum time to wait for the lock.unit
- time unit of the time argument.leaseTime
- time to wait before releasing the lock.leaseUnit
- unit of time to specify lease time.InterruptedException
void lock(long leaseTime, TimeUnit timeUnit)
After lease time, lock will be released..
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.
leaseTime
- time to wait before releasing the lock.timeUnit
- unit of time for the lease time.IllegalMonitorStateException
- if the current thread does not
hold this lockvoid forceUnlock()
Condition newCondition()
newCondition(String)
instead.newCondition
in interface Lock
UnsupportedOperationException
ICondition newCondition(String name)
ICondition
instance that is bound to this
ILock
instance with given name.
Before waiting on the condition the lock must be held by the
current thread.
A call to Condition.await()
will atomically release the lock
before waiting and re-acquire the lock before the wait returns.
name
- identifier of the new condition instanceICondition
instance for this ILock
instanceNullPointerException
- if name is null.boolean isLocked()
true
if this lock is locked, false
otherwise.boolean isLockedByCurrentThread()
true
if this lock is locked by current thread, false
otherwise.int getLockCount()
long getRemainingLeaseTime()
Copyright © 2016 Hazelcast, Inc.. All Rights Reserved.