89 How can we Call Join on Main Thread in Java?

Code :

public class Test  extends Thread
{
static Thread mt = null; // Main Thread 

@Override
public void run()
{
try
{
mt.join();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
for(int i=1;i<=10;i++)
System.out.println("run: "+Thread.currentThread().getName());

}


public static void main(String args[]) throws InterruptedException 
{
Test t = new Test();

t.setName(" CodingAtharva ");
mt = Thread.currentThread(); // main thread 
t.start();
for(int i =1;i<=10;i++)
{
System.out.println("main: "+Thread.currentThread().getName());
}
}
}




Output:




Previous
Next Post »