Skip to Content

SAP BO Logical Lock and Java Lock under Multiple-Node Server Environment

Dec 27, 2017 at 10:35 AM


avatar image

Hi Experts,

I ran into a problem with the current environment setting. The task I am currently assigned is to modify the logic of getting NON-repetitive serial number ("serNo") for BPM process under multiple-node server environment.

Here goes the logic:

1. Prepare the parameter needed to pass in to the SAP LogicalLock API

2. Create a CAF operation "run()" to simulate the invocation of "create()" method →

ExecutorService exec = Executors.newScheduleredThreadPool(1);

3. Invoke the create() method for 15 times

4. Implementation of create() method goes like this:

** retrieve the BO#1 object from table 1 (CAF BO)

** lock(BO#1 object.getKey(), MODE_WRITE)

** get the current serNo from table1 BO#1's attribute

** invoke a local method to apply the serNo++ calculation (SerNo is of type STRING)

** set the returned serNo (serNo + 1) to the BO object and update(BO#1)

** unlock(BO#1 object.getKey(), MODE_WRITE)

** create(serNo (serNo + 1)) → BO#2 is created in DB

And here is my approach:

1. Using Java lock (synchronized/ reentrantlock ...) → so that there will be no repetitive serNo generated under single node server condition. If there is a multi-node server + method of creating serNo invoked at the same time, I would get two identical serial number and get a SQLException in return since I put the "serNo" as the key upon creation (create(serNo)).

2. Using SAP logical lock → I tried to get the business object from CAF table and retrieve the key of the BO. After that, pass in the returned key as the parameter and set the lock mode to "MODE_WRITE" and lock that specific business object instance. After done so, complete the manipulating task (e.g. serNo++) and save it to the locked business object → create("SerNo + 1") → unlock the first record (actually I have been using the same business object to count the most up-to-date serNo). However, after triggering the run() CAF operation with "two times" (under very close time interval), I was able to write the BO with 15 new records but apparently the later attempt of such invocation returned EXCEPTION: CAFPessimisticLockException: The entity is locked by user XXXXXXXXXX

3. Is there a better way to solve such a problem under multiple server node? Like table locking??

If there is anything else I need to provide in more detail, please let me know. Thank you all for your time and help!

Kind regards,


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers