IMapTKey, TValueTryLock Method (TKey, Int64, TimeUnit, Int64, TimeUnit)Hazelcast .Net Client Class Library
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.8.2
Syntax

bool TryLock(
	TKey key,
	long time,
	TimeUnit timeunit,
	long leaseTime,
	TimeUnit leaseTimeunit
)

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: Boolean
true if the lock was acquired and false if the waiting time elapsed before the lock was acquired.
Exceptions

ExceptionCondition
ArgumentNullExceptionif the specified key is null.
Exception
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

Reference