WebSphere eXtreme Scale Administration Guide > Configure WebSphere eXtreme Scale > Map entry 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.
You can specify a locking strategy either:
- programmatically
- with XML
Specify optimistic locking strategy programmatically
import com.ibm.websphere.objectgrid.BackingMap; import com.ibm.websphere.objectgrid.LockStrategy; import com.ibm.websphere.objectgrid.ObjectGrid; import com.ibm.websphere.objectgrid.ObjectGridManagerFactory; ... ObjectGrid og = ObjectGridManagerFactory.getObjectGridManager().createObjectGrid("test"); BackingMap bm = og.defineMap("optimisticMap"); bm.setLockStrategy( LockStrategy.OPTIMISTIC );
Specify optimistic locking strategy using XML
<?xml version="1.0" encoding="UTF-8"?> <objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ibm.com/ws/objectgrid/config/objectGrid.xsd" xmlns="http://ibm.com/ws/objectgrid/config"> <objectGrids> <objectGrid name="test"> <backingMap name="optimisticMap" lockStrategy="OPTIMISTIC"/> </objectGrid> </objectGrids> </objectGridConfig>
Specify pessimistic locking strategy programmatically
import com.ibm.websphere.objectgrid.BackingMap; import com.ibm.websphere.objectgrid.LockStrategy; import com.ibm.websphere.objectgrid.ObjectGrid; import com.ibm.websphere.objectgrid.ObjectGridManagerFactory; ... ObjectGrid og = ObjectGridManagerFactory.getObjectGridManager().createObjectGrid("test"); BackingMap bm = og.defineMap("pessimisticMap"); bm.setLockStrategy( LockStrategy.PESSIMISTIC);
Specify pessimistic locking strategy using XML
<?xml version="1.0" encoding="UTF-8"?> <objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ibm.com/ws/objectgrid/config/objectGrid.xsd" xmlns="http://ibm.com/ws/objectgrid/config"> <objectGrids> <objectGrid name="test"> <backingMap name="pessimisticMap" lockStrategy="PESSIMISTIC"/> </objectGrid> </objectGrids> </objectGridConfig>
Specify a no-locking strategy programmatically
import com.ibm.websphere.objectgrid.BackingMap; import com.ibm.websphere.objectgrid.LockStrategy; import com.ibm.websphere.objectgrid.ObjectGrid; import com.ibm.websphere.objectgrid.ObjectGridManagerFactory; ... ObjectGrid og = ObjectGridManagerFactory.getObjectGridManager().createObjectGrid("test"); BackingMap bm = og.defineMap("noLockingMap"); bm.setLockStrategy( LockStrategy.NONE);
Specify a no-locking strategy with XML
<?xml version="1.0" encoding="UTF-8"?> <objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ibm.com/ws/objectgrid/config/objectGrid.xsd" xmlns="http://ibm.com/ws/objectgrid/config"> <objectGrids> <objectGrid name="test"> <backingMap name="noLockingMap" lockStrategy="NONE"/> </objectGrid> </objectGrids> </objectGridConfig>
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
Map entry locking
Related concepts
WebSphere eXtreme Scale client configuration
Integrate with Spring framework
System APIs and plug-ins
Near cache scenario