![](../icons/Hazelcast-IMDG-Logo-Orange_Dark_200px.jpg) | IHazelcastInstanceGetLock Method |
Returns the distributed lock instance for the specified key object.
Namespace:
Hazelcast.Core
Assembly:
Hazelcast.Net (in Hazelcast.Net.dll) Version: 3.12.1
SyntaxILock GetLock(
string key
)
Function GetLock (
key As String
) As ILock
ILock^ GetLock(
String^ key
)
abstract GetLock :
key : string -> ILock
Parameters
- key
- Type: SystemString
key of the lock instance
Return Value
Type:
ILockdistributed lock instance for the specified key.
Remarks
Returns the distributed lock instance for the specified key object.
The specified object is considered to be the key for this lock.
So keys are considered equals cluster-wide as long as
they are serialized to the same byte array such as String, long,
Integer.
Locks are fail-safe. If a member holds a lock and some of the
members go down, cluster will keep your locks safe and available.
Moreover, when a member leaves the cluster, all the locks acquired
by this dead member will be removed so that these locks can be
available for live members immediately.
ExamplesLock lock = hazelcastInstance.GetLock("PROCESS_LOCK");
lock.lock();
try
{
}
finally
{
lock.unlock();
}
See Also