File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to update the different client windows? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to update the different client windows?" Watch "How to update the different client windows?" New topic
Author

How to update the different client windows?

Bably Das
Greenhorn

Joined: Sep 17, 2009
Posts: 28
Hello all,

My problem is that I start the server and two client windows simultaneously. So in one client window I select a room and click the book button to book that room. The customer Id entry dialog is then displayed and I enter a 8 digit number to book that room.

In the second opened client window I do the same, that is, book the same room but with a different customer Id. Right now when I click the "Book" button in the second client window, the customer id entry dialog is displayed and when I enter a different 8 digit customer id, my JTable is refreshed with the old value of the customer Id as I entered in the first opened client window for that room. So my questions are:

1. Once the room is booked in the first client window how do I refresh the JTable data in the other opened client windows?

2. Where do I need to throw the RoomAlreadyBookedException and an error message to notify the second client that the room he/she is trying to book is already booked by the first client?

3. If the value of the customerId stays as entered by the first client for n number of clients, is my locking method working as expected?

Many thanks,
Bably Das

SCJP 1.5, SCJD (URLyBird 1.3.2)
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5539
    
  13

Hi Bably,

1/ there is no requirement which requires data refreshing in different client windows, so I would not implement that (refresh of data occurs when user hits search button).
2/ I throw that kind of exception in my business service and it's caught in my client (where I show an appropriate message).
3/ I don't think this behavior is related to the locking method. It means your business logic to check if the room is already booked is working. The lock method of the Data class has another purpose which is described excellently in the ScjdFaq.

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Bably Das
Greenhorn

Joined: Sep 17, 2009
Posts: 28
Thanks Roel for your quick reply.
I am completely happy with the 1st and the 2nd points you mentioned and have implemented them. But unsure about the third. I have gone thru the link you provided.

3/ I don't think this behavior is related to the locking method. It means your business logic to check if the room is already booked is working. The lock method of the Data class has another purpose which is described excellently in the ScjdFaq.


My book method does lock -> update -> unlock. Just wanted to confirm that if my lock method is working as per Roberto's lock test class, is it a certainty that my locking and unlocking mechanism are working as desired?

Thanks,
Bably Das
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5539
    
  13

If you can run Roberto's test case multiple times (incrementing the loop counter each time) without your application "hanging" for ever (that's a deadlock), your locking meachnism is just fine.
 
Don't get me started about those stupid light bulbs.
 
subject: How to update the different client windows?