![]() | SUMit Roster Software > Nut's Weekly > February 2001 > Locking | Nederlands · Search... |
Locking |
Monay, 19 February 2001 |
![]() | ||||||||
What to do when two users wish to update the same data at the same time?
Three solutions:
No lockingThis is the simplest form. The user that updates last will win, the law of the last speaker. |
||||||||||
User 1 | Reads A | Writes B | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Value in database | A | B | C | |||||||
User 2 | Reads A | Writes C | ||||||||
In the example above user 2 writes last. His 'C' wins. The 'B' of user 1 gets lost. | ||||||||||
Advantages
| Disadvantages
|
|||||||||
Pessimistic LockingThis means a blockade for others, as long as one user is busy with some data. The blockade ispessimistic, just in case an update will follow later. | ||||||||||
User 1 | Reads A | Writes B | ||||||||
Value in database | A | B | C | |||||||
User 2 | ![]() |
Reads B | Writes C | |||||||
Advantages
| Disadvantages
|
|||||||||
Optimistic LockingWith optimistic locking the blockade works afterwards, with a check for the right version.The database has date and time of the latest version. During a write action the application checks of the update is using data that is still valid. A user that works with outdated data has to redo his action. | ||||||||||
User 1 | Reads A 09:00 | Writes A 09:00 -> B | ||||||||
Value in database | A 09:00 | B 10:15 | C 11:30 | |||||||
User 2 | Reads A 09:00 | Writes A 09:00 -> C ![]() |
Reads B 10:15 | Writes B 10:15 -> C | ||||||
Advantages
| Disadvantages
|
|||||||||
January 2001
· Possession
· Home
· Locking
· Sock
· March 2001
Home · Search... |