Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Select or Select....for update nowait (data write concurrency issue)

843854Jul 29 2003 — edited Aug 15 2003
Hello everyone,

I am working on a jsp/servlet project now, and got questions about which is the better way to deal with concurrent writing issues.

The whole senario is described as following:
First each user is viewing his own list of several records, and each record has a hyperlink through which user can modify it. After user clicks that link, there will be a popup window pre-populated with the values of that record, then user can do the modifications. After he is done, he can either click "Save " to save the change or "Cancel" to cancel it.

Method1---This is the method I am using right now.

I did not do any special synchronization measures, so if user 1 and user2 click the link of same record, they will modify the record
at the same time, then whose updates will take effect depends on who submits the request later. If user1 submitted first, then user 2, user1
will not see his updates. I know with this method, we will have the problem of "Lost Updates", but this is the simplest and efficient way to handle this issue.

Method2--This is the method I am hesitating.
I am considering to use "Select....for update nowait " to lock a record when user1 has selected one record and intended to modify it. If user2 wanted to modify the same record, he is not allowed. ( by catching the sql exception.)But the issue I am concerned about is because the "select .. For update" action and "Update action" are not so consecutive as many transaction examples described. There could be a
big interval between " select " and "update" actions. You could not predict user's behavior, maybe after he open the popup window, it took him a while to make up his decision, or even worse, he was interrupted by other things and went away for the whole morning?.Then the lock is just held until he releases it.

And another issue is if he clicks "cancel" to cancel his work, if I use method1, I don't need to interact with server-side at all, but if user method2, I still need to interact with the server to release the lock.


Can someone give me some advice ? What do you do to deal with similar situation? If I did not make clear of the question, please let me know.

Thanks in advance !

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 12 2003
Added on Jul 29 2003
13 comments
680 views