aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes need help on update functionality Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "need help on update functionality" Watch "need help on update functionality" New topic
Author

need help on update functionality

Kumar Kam
Greenhorn

Joined: May 28, 2004
Posts: 2
Hi,
I am working on the Data implementation class and I am confused about the following situation:
1. Suppose User 1 is viewing some records.
1'.User 2 who is an admin is also viewing the same records.
2. User2 makes use of the update() method and updates a record. 2'.Immediately after that, User 1 books the same record.

Now, user 1 booked the record based on the data that was displayed but at the time of booking it was stale because user 2 had updated it.
So how do we take care of this problem? Please help me.
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Kumar,

Welcome to JavaRanch and this forum!

The issue you describe is solved by performing "optimistic" locking:

- you read a record for display
- just before updating, you grab a lock on the record
- you reread the record and check if it changed in the meantime
- if it changed, you don't update (you cancel your transaction) and throw some exception
- else you update normally.

The advantage of optimistic locking is that it improves concurrency (records are locked for a minimum of time). Its drawback is that for any transaction you know that it's valid only when it ends. BTW, such a locking scheme is said "optimistic" because it's based on the *hope* that records won't change in the meantime most of the time.

Regards,

Phil.
Kumar Kam
Greenhorn

Joined: May 28, 2004
Posts: 2
thanks a lot, Phillippe. This was very helpful. I have one more doubt.
I am planning to expose the "Book" functionality from the server (not the data class though). So, when the client calls server.book(...), should I send the original record data in the call so that book() method can compare the data and then update the record?
Otherwise, the client has to use the low level Data class methods to do the booking.
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Kumar,

So, when the client calls server.book(...), should I send the original record data in the call so that book() method can compare the data and then update the record?


Yes, that's exactly what you should do.

Regards,

Phil.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help on update functionality