Posts

Showing posts from 2013

What do you understand by the terms optimistic locking versus pessimistic locking?

Q.  What do you understand by the terms  optimistic locking  versus  pessimistic locking ? A. Optimistic locking  means a specific record in the database table is open for all users/sessions. Optimistic locking uses a strategy where you read a record, make a note of the version number and check that the version number hasn't changed before you write the record back. When you write the record back, you filter the update on the version to make sure that it hasn't been updated between when you check the version and write the record to the disk. If the record is dirty (i.e. different version to yours) you abort the transaction and the user can re-start it. You could also use other strategies like checking  the timestamp or all the modified fields (this is useful for legacy tables that don't have version number or timestamp column).  Note : The strategy to compare version numbers and timestamp will work well with detached hibernate objects as we...