Attempt to lock the specified item within the specified period of time.

Namespace: Tangosol.Net.Cache
Assembly: Coherence (in Coherence.dll) Version: 12.1.2.0 (12.1.2.0)

Syntax

C#
public virtual bool Lock(
	Object key,
	long waitTimeMillis
)

Parameters

key
Type: System..::..Object
Key being locked.
waitTimeMillis
Type: System..::..Int64
The number of milliseconds to continue trying to obtain a lock; pass zero to return immediately; pass -1 to block the calling thread until the lock could be obtained.

Return Value

true if the item was successfully locked within the specified time; false otherwise.

Implements

IConcurrentCache..::..Lock(Object, Int64)

Remarks

The item doesn't have to exist to be locked. While the item is locked there is known to be a lock holder which has an exclusive right to modify (calling put and remove methods) that item.

Lock holder is an abstract concept that depends on the IConcurrentCache implementation. For example, holder could be a cluster member or a thread (or both).

Locking strategy may vary for concrete implementations as well. Lock could have an expiration time (this lock is sometimes called a "lease") or be held indefinitely (until the lock holder terminates).

Some implementations may allow the entire cache to be locked. If the cache is locked in such a way, then only a lock holder is allowed to perform any of the "put" or "remove" operations.

Pass the special constant LOCK_ALL as the key parameter to indicate the cache lock.

Expensive: Locking always occurs on the back cache.

See Also