Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes read access locks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "read access locks" Watch "read access locks" New topic
Author

read access locks

Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
I was asked a question in the interview..the question was like say 2 Users(say user A and user B) access a JSP page.This JSP page will display "count" and say currently the "count" value is 10.So both Users see "count" value as 10.Now this JSP has a "submit" button,and when the user clicks on that submit button,then their count should be increased by 1.Now the User A clicks on submit button,and the count increases by 1,so the count value becomes "11".But User B still sees 10,and now say User B hits submit button as well.Now instead of count increasing to "12",we should display an error message to the User B saying someone has already updated the "count" variable. How can this be achieved...

I thought either through timestamp or may be transaction.


Man Suraj
Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Yes. Using a timestamp will do. The timestamp rill be updated on save. Before saving though, check the timestamp to see if it has changed. If it's the same as when data was read, proceed with update. Else, re-read the count, then do the update.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
Thanks....
Is there anything i could do with transaction here to solve the problem
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

There is no transaction support in servlets. Are you thinking about EJBs?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
Hmm....i have no idea what is the solution of this question....so am really not sure in which forum to put this question in...And please dont expect me to put the same question in all forums...The main thing i have posted this question was since i had no CLUE of the answer....so i need help there
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: read access locks