SynchronizedDictionaryAcquireReadLock Method (Int32) |
Oracle® Fusion Middleware .NET API Reference for Oracle Coherence
14c (14.1.1.0)
F23534-02
Acquire a read lock.
Namespace:
Tangosol.Util.Collections
Assembly:
Coherence (in Coherence.dll) Version: 14.1.1.14 (14.1.1.14)
Syntaxpublic bool AcquireReadLock(
int timeout
)
Parameters
- timeout
- Type: SystemInt32
Timeout in milliseconds.
Return Value
Type:
Booleantrue if a lock was acquired within the specified time,
false otherwise.
Remarks
This method will attempt to acquire a read lock for up to
timeout milliseconds, and will return a boolean
value specifying whether or not the lock was acquired successfully.
Multiple threads can hold read locks at the same time, but no
thread will be able to acquire a write lock until all read locks
are released.
This method should always be used in combination with a
ReleaseReadLock method in the following manner:
if (dict.AcquireReadLock(timeout))
{
try
{
}
finally
{
dict.ReleaseReadLock();
}
}
This will ensure that the dictionary is not accessed unless the
lock was acquired successfully, and that the lock is released
properly even if an exception is thrown by the code within the
try block.
It is entirely up to you how to handle the case when the
AcquireReadLock method returns false. For example,
you can ignore the fact, throw an exception, or retry the
operation by placing the code above within a loop.
See Also