Hi,
I have a web application (no ejbs) that is used by admins and web users. my question is, if a web user wants to update his info in the mean time an admin is updating the same users info there will be a lock in the database. I am not sure how to prevent this from happening from within my application.
Ideas?
A
-
Database Locks in a web application (2 messages)
- Posted by: ahmed tantan
- Posted on: July 11 2003 17:59 EDT
Threaded Messages (2)
- Database Locks in a web application by stephen smithstone on July 12 2003 17:21 EDT
- Database Locks in a web application by Pietari L on July 24 2003 22:11 EDT
-
Database Locks in a web application[ Go to top ]
- Posted by: stephen smithstone
- Posted on: July 12 2003 17:21 EDT
- in response to ahmed tantan
there could be a couple of ways add an application level varible that is enable when i user is updating their info and then check that before you go to update the info , add an extra field into the database that is checked etc etc -
Database Locks in a web application[ Go to top ]
- Posted by: Pietari L
- Posted on: July 24 2003 22:11 EDT
- in response to ahmed tantan
Depending on what kind of transactions you do and your DB server, as well as transaction isolation levels, a deadlock or a concurrency conflict is possible. For example:
The user SELECTs the current info in transaction T1
The administrator UPDATEs the current info in transaction T2
Transaction T2 commits
User tries to UPDATE in transaction T1...but meanwhile the administrator has changed the data. This is a concurrency conflict.
Different DB servers handle this situation differently. The exact behavior also depends on your transaction isolation level settings. Check the documentation for your database to check what exactly would happen.
To prevent the conflicts from happening, you can use 2 methods:
1) Locking the data
2) Trying the transaction again
Option 1) often suffers from the risk of deadlock. You should analyze the situation and see if such a risk exists. If you can live without transactions, though, everything becomes much easier.
Pietari Laurila