![](../icons/Hazelcast-IMDG-Logo-Orange_Dark_200px.jpg) | IMapTKey, TValueTryLock Method (TKey, Int64, TimeUnit, Int64, TimeUnit) |
Tries to acquire the lock for the specified key for the specified lease time.
Namespace:
Hazelcast.Core
Assembly:
Hazelcast.Net (in Hazelcast.Net.dll) Version: 3.9.4
Syntaxbool TryLock(
TKey key,
long time,
TimeUnit timeunit,
long leaseTime,
TimeUnit leaseTimeunit
)
Function TryLock (
key As TKey,
time As Long,
timeunit As TimeUnit,
leaseTime As Long,
leaseTimeunit As TimeUnit
) As Boolean
bool TryLock(
TKey key,
long long time,
TimeUnit timeunit,
long long leaseTime,
TimeUnit leaseTimeunit
)
abstract TryLock :
key : 'TKey *
time : int64 *
timeunit : TimeUnit *
leaseTime : int64 *
leaseTimeunit : TimeUnit -> bool
Parameters
- key
- Type: TKey
key to lock in this map. - time
- Type: SystemInt64
maximum time to wait for the lock. - timeunit
- Type: Hazelcast.CoreTimeUnit
time unit of the time argument. - leaseTime
- Type: SystemInt64
time to wait before releasing the lock. - leaseTimeunit
- Type: Hazelcast.CoreTimeUnit
unit of time to specify lease time.
Return Value
Type:
Booleantrue if the lock was acquired and false
if the waiting time elapsed before the lock was acquired.
Exceptions
Remarks
Tries to acquire the lock for the specified key for the specified lease time.
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:
-
the lock is acquired by the current thread, or
- the specified waiting time elapses.
Warning:
This method uses hashCode and equals of the binary form of
the key, not the actual implementations of hashCode and equals
defined in the key's class.
See Also