| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
|  |  | |||
Home -> Community -> Usenet -> c.d.o.misc -> Re: optimistic/pessimistic locks
Hi,
Robert Chung wrote:
> What are optimistic/pessimistic locks?  I have five Oracle books and
> none of them has any reference to these locks.  Thanks in advance.
If you are talking about optimistic locking  addressed in Oracle Web
Application Server this means that lockingcan't be be done if you use a
Web interface.
Consider the following scenario :
 User A  retrieves a  HTML page containing a form  with  some or alle
fields  field from the database
 and now able to be changed be the user.
Since HTTP is a stateless protocol, once data is retrieved from database there is no lock on the rows when the user start changing fields. If it would be something like Oracle FORMS, as soon as a user starts editing a row, the row is locked in the database. But which HTTP you hardly can implement such features. Because you don't know if the user surfs from the page away. The server will never know that. So locking a row when user request data via the web could quickly lock a complete table or will lead to dead locks.
Furthermore, there is no implementation that would keep up the lock since a web call is usally implemented by single thread executing. Which ceases to exist when the HTML output is generated.
Therefore so called optimistic locking exists, which is nothing else than either coding all values of involved fields as Hidden fields in a HTML form or generating a checksum upon all involved fields.
If the user (ever) send the form back to the server, you can recalculate the checksum with database data at this moment. If somebody else has changed any field in the meantime you can notice the user and take whatever action is appropriate.
So optimistic locking in this context means that you hope nobody will update the row (s) the user is currently working on. You don't lock rows you check before update if data in database is still the same as it was when you started off.
I never heard about pessimistic locking. Would be intresting what that should be ?
Regards,
  Robo.
Received on Sun May 31 1998 - 18:39:42 CDT
|  |  |