[.net programming language only]

Configuring and implementing locking in .NET applications

For the backing maps that you are accessing from WebSphere® eXtreme Scale Client for .NET, you must define a pessimistic locking strategy. You can also override the lock timeout value for a map instance. After you configure locking, you can lock individual keys or a list of keys in the map.

Before you begin

Procedure

  1. Configure a pessimistic locking strategy in the backing map.
    The WebSphere eXtreme Scale Client for .NET supports the pessimistic locking strategy only. For more information, see Configuring a locking strategy in the ObjectGrid descriptor XML file.
  2. Override the lock wait timeout for a single IGridMapPessimisticTx instance.
    Use the IGridMapPessimisticTx.LockTimeout property to override the lock timeout value for a specific IGridMapPessimisticTx instance. The lock timeout value affects all transactions started after the new timeout value is set. This method can be useful when lock collisions are possible or expected in select transactions.
  3. Lock individual keys or a list of keys in the map.
    Use the Lock method to lock the key in the data grid or lock the key and determine whether the value exists in the data grid.
    • The following method locks the key in the map, returning true if the key exists, and returning false if the key does not exist.
      bool IGridMapPessimisticTx.Lock(Tkey key, LockMode lockMode);
    • The following method locks a list of keys in the map, returning a list of true or false values; returning true if the key exists, and returning false if the key does not exist.
      IList<bool> IGridMapPessimisticTx.LockAll(IList<TKey> keyList, LockMode lockMode);
      LockMode is an enum with possible values where you can specify the keys that you want to lock:
      • [Version 8.6 and later]Shared, Upgradable, Exclusive
    An example of setting the LockMode parameter follows:
    ptmap.Transaction.Begin();
    ptmap.Lock(key, LockMode.Upgradable);
    ptmap.Put(key,value);
    ptmap.Transaction.Commit();