Forums Register Login

implement book by socket.

+Pie Number of slices to send: Send
Hi:
I am using socket to implement the assignment.
I asked a question about lock/unlock before,
With member's help, I do it in the background on
server side. But I am confused on how to notify client after unlock. Because I use socket, if the client wait for reply, code like this
while( true ) {
fromServer = in.readLine();
}
the client have to do nothing until the result of booking ticket come back. How to implement it?
Thanks.
Paul
+Pie Number of slices to send: Send
Hi Paul,
The best way to avoid a busy wait, is to call wait() on the object and after the event that you are waiting on occurs call notifyAll(). It is quite simple to do this in Java using the Observer interface and by having the class that you are wait()ing for extend Observable. The Observable calls setChanged() and notifyObservers() when the event completes and in turn the update() method on the Observer is called. So in your update() method on the Observer you could call notifyAll() to release the thread that is waiting for the event to complete.

Hope this helps,
Michael Morris
+Pie Number of slices to send: Send
Hi Michael:
Thank you for your reply. But the problem is my design is view -> model -> dbclient, I have used Observer pattern on view-model, the model class extends Observable, so that I can not use it on
db client and model. And the db client is not a thread, when client need send data to server it will be called and work for it. So if client wait for the reply continuelly, user can do nothing at that time.
Thanks.
Paul
+Pie Number of slices to send: Send
Hi:
I can not work it out. If I make user wait reply and can not input( or other things) until info received from server, is it all right?

Is there somebody implement assignment with sockt?
Paul.
+Pie Number of slices to send: Send
Hi,
I think making the client wait till a response arrives from server is the best way to do it. Otherwise each request to server should be done in a seperate Thread. I think a single Threaded model is just fine. This is a common problem no matter the implementation is Sockets or RMI. In both the implementations, the call will wait till lock is acquired. I think this approach is quite OK. But dont know for certain since I am also doing the assignment and have not submitted yet.
regards Jacob
+Pie Number of slices to send: Send
Hi:
I think client wait for reply may not be a only way but at least it is simple to implement.
To image that you book tickets on web site,
after push book button on a web page, you have to wait the response. Can you book an ticket or do other things at that time? I think you can not.
ok, I make it wait until the reply arrive.
Thank you for reply. You give me a great help.
Paul
+Pie Number of slices to send: Send
Hi Paul,
All of my booking requests occurred on a separate thread. I also had a problem with Observer like you, so I implemented a "roll-your-own" Observable to overcome the problem. I just kept a Set of Observers and in my home grown notifyObservers() method, called update() on all the registered Observers.
Running each booking operation in a separate thread overcomes the problem of a deceased client that may have owned the lock when it died. So long as you have provided a means to release those locks at some point.
Hope this helps,
Michael Morris
What a stench! Central nervous system shutting down. Save yourself tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 835 times.
Similar Threads
lock() called twice by same client
Doubt regarding locking & unlocking
lock and unlock
Lock design comments
Locking - Notification issues
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:53:30.