Hi,
I was going through threads and tried a little code myself and found that it is quite difficult to understand the execution of main
thread and child threads.
Please look at the following code...
Now, when I run this code it always prints.....
start method
Run method
Run method
Run method
Case 1.....
===========
If I change the main method like this..
public static void main(
String[] args)
{
Thread t= new Thread(new StartRun());
t.start();
Thread t1= new Thread(new StartRun());
t1.start();
new StartRun().start(); Thread t2= new Thread(new StartRun());
t2.start();
}
It prints
start method
Run method
Run method
Run method
Case 2
=======
If I change the main method like this
public static void main(String[] args)
{
new StartRun().start(); Thread t= new Thread(new StartRun());
t.start();
Thread t1= new Thread(new StartRun());
t1.start();
Thread t2= new Thread(new StartRun());
t2.start();
}
It prints
start method
Run method
Run method
Run method
I am confused about the behaviour of execution of start method of StartRun class and the execution of threads.
Please someone explain this.
Thanks
Kaps
[ October 31, 2004: Message edited by: kapil munjal ]