Dear Guys,
Below is a simple programme.....
class FunnyThreads implements Runnable
{
public void run()
{
try
{
for(int i =0;i<3;i++)
{
System.out.println("Child threads "+i);
Thread.sleep(1000);
}
}
catch(InterruptedException ie)
{}
System.out.println("exiting child");
}
public static void main(
String[ ] args)
{
FunnyThreads ft = new FunnyThreads();
Thread t = new Thread(ft);
t.start();
try
{
System.out.println("Main thread");
Thread.sleep(500);
}
catch(InterruptedException ie){}
System.out.println("Main Exiting");
}
}
According to some books Like Complete refrence(Patrick)...The main should exit at last else the system will hang...and moreover I think after Main exits there should not be further execution of the programme.....And here is the out put of above programme....
---------- run ----------
Main thread
Child threads 0
Main Exiting
Child threads 1
Child threads 2
exiting child
Normal Termination
Output completed (4 sec consumed).
------
here main() has exited long back...but there is normal termination of the programme.....
CAN SOMEBODY EXPLAIN ME WHY IS THIS SO???
INTRESTING HUH!!!
Thanks,
Harpal