Program guide > Access data with client applications > Programming for transactions > Use locking



Configure a locking strategy

You can define an optimistic, a pessimistic, or no locking strategy on each BackingMap in the WebSphere eXtreme Scale configuration.

Each BackingMap instance can be configured to use one of the following locking strategies:

  1. Optimistic locking mode

  2. Pessimistic locking mode

  3. None

The default lock strategy is OPTIMISTIC. Use optimistic locking when data is changed infrequently. Locks are only held for a short duration while data is being read from the cache and copied to the transaction. When the transaction cache is synchronized with the main cache, any cache objects that have been updated are checked against the original version. If the check fails, then the transaction is rolled back and an OptimisticCollisionException exception results.

The PESSIMISTIC lock strategy acquires locks for cache entries and should be used when data is changed frequently. Any time a cache entry is read, a lock is acquired and conditionally held until the transaction completes. The duration of some locks can be tuned using transaction isolation levels for the session.

If locking is not required because the data is never updated or is only updated during quiet periods, you can disable locking by using the NONE lock strategy. This strategy is very fast because a lock manager is not required. The NONE lock strategy is ideal for look-up tables or read-only maps. For more information about locking strategies, see Locking strategies .

You can specify a locking strategy programmatically or with XML. For more information about locking, see Locking strategies.


Procedure


What to do next

To avoid a java.lang.IllegalStateException exception, call the setLockStrategy method before calling the initialize or getSession methods on the ObjectGrid instance.


Parent topic:

Use locking


Related concepts

Locks

Locking performance best practices

Map entry locks with query and indexes


Related tasks

Implement exception handling in locking scenarios

Configure the lock timeout value