Hello everyone,
I have some doubts about locking in the WAS.
According to help.sap.com there are two ways of locking data in a DB table:
1. Use the Enqueue Server;
2. Use DB locking.
I have developed a Session Bean which has a simple method to always update the same DB table record.
Then I developed a client (portal app) invoking the bean method within a loop:
Something like:
for (int i=0; i<10000; i++) {
//Call bean method to update always the same table row with a diferent number
}
Then I put two clients to run concurrently to see the result;
And the result was:
1. About 50% of LockExceptions when I was using the enqueue server (using JDBC to get the connection and using the TableLocking API to lock the data).
2. 0% of locking collisions when I was using database locking.
The point is:
I am doing something wrong?
It seems that when locking with the DB (even with the lowest isolation level) the updates are much more faster than using the Enqueue Server since no collisions occur with DB locking and about 50% of collisions occur with the Enqueue Server.
What are the advantages of using the Enqueue Server then? Only for portability reasons?
Furthermore, in the case I am developing an application without user interaction, how should I deal with the LockExceptions? By trying again after some period of time? In that case, can you suggest a good/best alghoritm to implement that delay inside a session bean business method (as for my low understanding of EJBs one cannot manipulate threads inside a EJB, isn't it?)?
Thanks a lot for your time,
Diz