InventoryManager includes the acquireInventoryLocks and releaseInventoryLocks methods. These methods can be used to prevent deadlocks in the database, especially if there are multiple Oracle ATG Web Commerce instances concurrently updating inventory.

acquireInventoryLocks acquires locks for the inventory items that apply to the given IDs. releaseInventoryLocks releases locks for the inventory items that apply to the given IDs.

RepositoryInventoryManager implements acquireInventoryLocks by calling RepositoryInventoryManager.lock for each id (plus each id within a bundle). It does not implement releaseInventoryLocks since those locks will be released automatically with the end of the transaction.

The following example demonstrates how to use these methods to prevent deadlocks:

void myPurchase(List pCatalogRefIds, long pQuantity)
{
   InventoryManager im = getInventoryManager();
   try {
      im.acquireInventoryLocks(pCatalogRefIds);
      Iterator idIterator = pCatalogRefIds.iterator();
      int success;
      while(idIterator.hasNext()) {
         String id = (String) idIterator.next();
         success = im.purchase(id, pQuantity);
         . . .
      }
   }
   finally {
      im.releaseInventoryLocks(pCatalogRefIds);
   }
}

Copyright © 1997, 2013 Oracle and/or its affiliates. All rights reserved. Legal Notices