On Wed, 26 Jul 2000 10:51:20 +0100, Lahooti, Hamid
<[EMAIL PROTECTED]> wrote:
>David Wall <[EMAIL PROTECTED]> wrote:
>>>Optimistic locking cannot mean "you won't have deadlock."
>>Yes it does. Deadlocks are prevented by keeping several versions of the
>>same instance (one for each tx), hence there will be no deadlocks since
>>two tx's cannot lock on the same instance.
>
>No it doesn't. Consider the following scenario:
>TX1 updates A, intends to Update B, cannot see TX2's updates to B,
>TX2 updates B, intends to Update A, cannot see TX1's updates to A
>
>If A and B could see that their intended record has been modified,
>they could rollback back (principal of optimistic locking) back but
>transaction isolation ensures they cannot see each others updates.
>Hence we have a deadlock situation.
And what does this have to do with optimistic locking? You are still
thinking in terms of pessimistic locking.
What matters is whether TX1 or TX2 commits first. If TX1 commits first,
then TX2 cannot commit since one or more record(s) that it has modified
was modified between the time the transaction was started and the time
it was committed.
This is the difference between optimistic and pessimistic locking (hence
the names):
Pessimistic locking LOCKS the data it has used so that noone else can
use it until the tx has commited. I.e. always assume that things can go
wrong.
Optimistic locking doesn't really lock the data, but instead determines
at commit time whether the tx that is commiting will conflict with the
results of another concurrent tx. I.e. always assume that things work
out, but in the rare case that they don't: rollback.
Do you agree?
/Rickard
--
Rickard �berg
Email: [EMAIL PROTECTED]
http://www.telkel.com
http://www.jboss.org
http://www.dreambean.com
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".