I have come to believe that threads have a very unpredictable output.But what i want to know is what is the path they follow for executiom.what happens after i call run()
here is a sample problem.
class NewThread implements Runnable
{
Thread t;
NewThread()
{
t=new Thread(this,"Demo Thread");
System.out.println("Child thread: "+t);
t.start();
}
public void run()
{
try
{
for(int i=5;i>0;i--)
{
System.out.println("Child Thread: "+i);
Thread.sleep(1500);
}
}
catch(InterruptedException e)
{
System.out.println("Child Interrupted");
}
System.out.println("Exiting Child Thread");
}
}
class ThreadDemo
{
public static void main(
String args[])
{
new NewThread();
try
{
for(int i=5;i>0;i--)
{
System.out.println("Main Thread: "+i);
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
System.out.println("Main Thread Interrupted.");
}
System.out.println("Main thread Exiting.");
}
}
I am able to make threads but what i fail to understand is the process after start() is called