Accessing thread from called class
Hello
I have a Java class (an applet) which spins off a separate thread to handle
socket networking communication code. I pass the this ref to the new spun
off thread so the thread class can communicate with the applet GUI.
However, if I for example, click on a button in the applet, I want to pass
the request onto the networking thread.
So questions are:
1. How do I invoke a method in the spun off thread from the applet? My
thread looks like this:
// class ThreadNetworkhandler
class ThreadNetworkHandler extends Thread
{
private CubaThread m_Object;
// Constructor
ThreadNetworkHandler(CubaThread obj)
{
m_Object = obj;
}
public void run()
{
// do stuff here eg m_Object.lst.addItem("blah...");
}
}
And I spin it off like this:
t = new ThreadNetworkHandler(this);
t.start();
Where t is of type Thread - a member variable of the applet class.
Do I just implement eg a SendCommand() function (or whatever name you like)
in the ThreadNetworkHandler class and call that?
2. Another question on same sort of topic. Should I have one thread for
incoming socket communication stream and another for the outgoing?
Any feedback would be much appreciated.
Angus