wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes Implementing multi-threading in a Standalone client-server environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Implementing multi-threading in a Standalone client-server environment" Watch "Implementing multi-threading in a Standalone client-server environment" New topic
Author

Implementing multi-threading in a Standalone client-server environment

Denise Advincula
Ranch Hand

Joined: Jan 01, 2007
Posts: 160
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!


SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCMJEA in progress...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41598
    
  55
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.


Ping & DNS - my free Android networking tools app
Denise Advincula
Ranch Hand

Joined: Jan 01, 2007
Posts: 160
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..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Implementing multi-threading in a Standalone client-server environment