Do optimistic locks work for multiple applications

439 Views Asked by At

Multiple servers use the same database,when they access the same data by optimistic locks.Sever A,server B get the data of version 1,and they commit at the same time with the version 2. Do optimistic locks work for multiple applications?

1

There are 1 best solutions below

2
Luaan On

If you're actually using optimistic locks, of course they work for multiple applications. That's the whole point of optimistic locks - you don't really need them in a single application.

But they need to be optimistic locks, not just "let's hope it doesn't break". That means that an update of the row must always result in a new version number. When A and B try to do the update, the first that actually goes through will have the old version incremented, which means the other will no longer have a matching version, and will get an optimistic concurrency fail.