wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Concurrency Problems - Booking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Concurrency Problems - Booking" Watch "Concurrency Problems - Booking" New topic
Author

Concurrency Problems - Booking

George Walker
Greenhorn

Joined: Apr 24, 2005
Posts: 2
Hi,

Wondering if anyone knows how to solve this problem or can provide some guidance.

I'm trying to complete the URLyBird application booking method.

How do I solve this problem: -

1) Client searches for a hotel and gets matching list.
2) Admin uses update on one of the records that the client is interested in. To say, change the location or hotel name, or even max number of persons etc.
3) Client now wishes to book the record as it was previously described. (their JTable has not been refreshed)
4) Client clicks book and thinks that they are booking the record as previously described, but are infact booking a different hotel (as amended by the admin).

The only thing that I am currently checking for during booking is that the record has not been deleted or booked by another client, but what if the record is updated as described above?


Just wondering how other people went about solving this one?

thanks,
George
Frans Janssen
Ranch Hand

Joined: Dec 29, 2004
Posts: 357
Hi George,

You made an interesting observation!

But I think your worries are beyond the scope of the assignment, so as long as you will check for existance of the record and that it is not booked, you will be doing enough.

However, if you want, you can verify (after locking the record) that the record still contains the same data as when it was last read. If this is not the case you could warn the user. But again, I think that is beyond the scope, so I wouldn't bother with it.

Frans.


SCJP 1.4, SCJD
George Walker
Greenhorn

Joined: Apr 24, 2005
Posts: 2
Frans,

I've changed my booking method so that it takes a further argument, the String[] data of the currently selected record in the view. Then once I lock the record to be booked I compare the view record data against the newly read row from the db and if the descriptions differ, then I warn the user, end the booking, and refresh the table to show what has changed.

thanks for the help,


George.
Liang Anmian
Ranch Hand

Joined: Jun 25, 2004
Posts: 119
Yes, interesting observation. I solved this problem using RMI Callback to allow automatic update of clients from the server.

I'm not completely sure if this actually solves the problem. But well, at least the client doesn't have to repeatedly refresh the table.


Current Status:<br /> <br />SCJP 1.4<br />SCJD (in progress)
David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
Originally posted by Liang Anmian:
I solved this problem using RMI Callback to allow automatic update of clients from the server.


Could someone please elaborate on what "RMI Callback" is? I had this same question and the consensus on the forum was not to worry about implementing updates from the server to the clients everytime a change was made to the remote database - this was considered beyond the scope of the assignment.

I'm not that experienced with RMI and I don't see any "Callback" class in the JDK1.4.2 API for RMI (I'm not using the 1.5 Tiger release). Any idea what Liang is referring to here? Thanks.
Wei-ju Wu
Ranch Hand

Joined: Feb 16, 2005
Posts: 147
Callbacks are a concept in distributed computing. Clients can register themselves with the server in a similar way like you would add an event listener to a Swing component.

If a data update is performed on the server, the server can call the client's notification function, possibly containing only the changed data. This concept can solve the problem of keeping the client's data up to date, a related design pattern would be the Observer pattern.

I did not implement this since I thought it was not needed, but in RMI, it would involve defining and implementing a remote interface for the client, for data change notification and adding a addYourChangeListener(YourListenerInterface) function to your server.


"The UrlyBird catches the certificate. And he's gonna FlyByNight"<br /> <br />SCJP 1.2/5.0, SCJD, SCBCD, SCWCD, SCEA
David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
So does that mean that there is no built in function in the RMI API to handle server side callbacks? It sounds like you have to build your own listener interface (for the client) and the means to add the interface as a listener to the server.

I actually tried this, using a javax.swing.event.EventListenerList with a ChangeListener as my interface. The problem I ran into was that everything had to be serializable to communicate between the server and client. This caused more problems to resolve. In order to update my clients from the server I had to pass my GUIController from my server to client since it was specific to each client and would handle the updating of the client. But all class variables had to be serialized and if I made them transient, then they would remain null, so this would break my GUIController functionality.

I decided to just refresh the client whenever the user does some action with it. I understand this to be acceptable for this assignment.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Concurrency Problems - Booking
 
Similar Threads
delete record, update gui
B&S: Booking a changed or replaced record.
NX: should data update broadcasted to all users?
is Unreferenced a bad idea ?
Update Issue