• Advertisement
Sign in to follow this  

[java] Multithreading Class Sending Data To The Main Class?

This topic is 2404 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm new to Java and I haven't really tacked this type of issue, but since my source code is pretty big I'll break it down so it's very easy to understand my problem without using a lot of source code.

So I have a client/server merged into one app and made two classes. The 1st class is the main class which handles the frame and holds the variable of the 2nd class. This second class does networking and multithreading into one. So of course I can very easily pass variables from the main class to the second class in a variable form. But what if ... I want to lets say create a message dialog when ever a client connects in the second class of a thread. So when the user clicks okay I can access private/public variables and change their value of the main class? I was thinking of maybe creating a event listener in the main class that the second class can call and be able to pass values, but I'm not sure if thats the best option.

Thanks, Andrew.

P.S I'm using this multithreading type of class:


public class MyThread implements Runnable {

public void run() {
.....
}

}


public class DoNetworkingAndThreading
{
public void IDoSomeWork()
{
//Calls the MyThread in a separate thread...
}

}

Share this post


Link to post
Share on other sites
Advertisement

You need to find or write a thread safe communications mechanism to allow your networking thread to notify the UI of events, such as a new client. You need to be extremely careful touching variables that can be accessed by more than one thread. You really need to understand the core principles of concurrent programming to get this right.



Yeah as above threading and synchronization is quite complex. Here a link to what I would use for your problem:

http://download.orac...y/syncmeth.html

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement