Here is a code snippet to properly lock and unlock an object with using the transaction locking mechanism. The example is for a custom object, but can be used for any sailpoint.object that extends SailPointObject. For an Identity object and other objects (Certification) that should use the persistent locking mechanism, refer to the lockIdentity, lockCertificationById methods in the ObjectUtil class.
import sailpoint.api.ObjectUtil;
import sailpoint.object.Custom;
//Get the Transaction lock
Custom custom = ObjectUtil.transactionLock(context, Custom.class, custObjName);
try {
//Modify the object
custom.put(key, val);
//Save the modifications in the Try block
context.saveObject(custom);
} catch (Exception e) {
//Log any errors encountered during saving the object
log.error(e);
} finally {
//Commit the transaction
context.commitTransaction();
}
context.decache(custom);