Am i clear? Let me know if not.
Main Topics
Browse All TopicsHi All
I have question on Record Lock in Java.
I have this Situation.
In our web application, a user can login and search all the (some product )cases which are open.
He opens up this case, see the details and click on EDIT button to edit the case.
At the same time another user logins and tries to edit or delete.
Then a message should pop up saying, the record is locked.
How do i lock the record for one particular user, and unlock after he is done updating ?
Tha application is built on Struts.
Thanks
Vinay
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
What happens if the first User clicks on Edit and then he never actually saves the updated values(or the browser dies, network goes down etc etc). The Record will be locked on forever and no one would unlock the record.
A good approach is to have concurrency check in the system using version numbers. Have a version number column in the database table. Both Users A and B get the record say with version 6. A updates the record and saves it. The version is updated to 7. Now B saves the record. The versin of B is 6 and in db is 7. If the versions do not match, throw an error indicating the same and do not update the record.
Locking the Record on clicking the Edit button will have the problem that I mentioned above. There is no guaranteed way of unlocking the record.
Business Accounts
Answer for Membership
by: alexander_ivanovPosted on 2006-02-25 at 02:14:31ID: 16044886
Hello,
I see two solutions. First one is lock record on database level, you have to do some tuning on database and lock correspondent record(s) when user start edit. Then when another user tries to edit same record exception will be thrown, your programm will catch this exception and inform second user. This way is most sure, because of database will forbid any concurrent modifications.
Second solution is to keep opened records in static ArrayList(for example) and every time user try to edit something programm will check if this record exists in that ArrayList. When record is not in list then add it into list and allow edit, or show alert otherwise.