Hello there,
I'm not really new to Java, I've been busy with it for quite some time now
I'm trying to make a threaded server now, but I can't figure something out about threads.
I have a main thread/class and a thread, in my thread I call a method in the main class. My question is; Will the method be executed in the main thread or in the thread?
For those who don't understand my question:
I have a main thread, kinda like this:
//Main class
public class Main
{
public static void main(String args[])
{
ThreadA thread=new ThreadA(this);
thread.start();
}
public void doAlotOfWork(int number)
{
//Do some hard calculations, etc.
}
}
And a thread class, like this:
//Constructor
public ThreadA(Main main)
{
this.mainThread=main;
}
public void run()
{
mainThread.doAlotOfWork(10);
}
**Note** I have made the code abit shorter, so it's easier to read
**Note**
Which thread will do all the work?
ThreadA; because he calls the funtion so he does the job.
Or
Main Thread; The function is in the Main class, so he does the job.
I have tried some things with the threads, and as far as I can see, ThreadA will do all the work, but I'm not sure, so can anybody tell me if the Main thread or the ThreadA will do all the work?
Thank you for your time,
Wesley
[edited by - wicked_wesley on January 11, 2004 2:30:44 PM]
[edited by - wicked_wesley on January 11, 2004 2:32:12 PM]