• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing multi-threading in a Standalone client-server environment

 
Denise Advincula
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I want to do a standalone client-server application using multi threading. My client constantly checks for updates from the server. Meanwhile, my server is waiting for updates as well from some utility which uses a timer to determine when to change the update.

Here's how I did it:

I have a Rate object, with a rateStatus attribute, and a statusChanged method. I used the Thread's name to represent the status.





1) I have a Main program, which does starting of the two threads:


2) My ClientJob which gets the Rate Status


3) My ServerJob which just updates the RateStatus after some seconds:


4) and a Bank Util code where the rate in question actually resides.



... it's already OK (I think..) except that my Client thread is not notified everytime I run main. My output is like this:



I want my Client thread to be notified for every status change.. But how come my client thread doesn't recognize the notify because it prints only the last status..
I want my output to be like this:



But it seems that the Client Thread runs after the server thread run..


I hope you can help me with this. Thank you!

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
out.println("Status is "+status);
Rate.getStatus()

What does the getStatus method do? Its result doesn't seem to get used, and the code you posted of the Rate class doesn't have any such static method. Is this actual working code?

I used the Thread's name to represent the status.
What exactly do you mean by that? I see only a single place where the thread name is set (to "BPI"), and then never again, although it is checked in the "statusChanged" method.
 
Denise Advincula
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry my code seems confusing.. I figured it out now, the secret is the object should hold the notification power when it figures that there is an update from the server..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic