Code :
public class Test extends Thread
{
static Thread mt = null; // Main Thread
@Override
public void run()
{
System.out.println("run: "+Thread.currentThread().getName());
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();
System.out.println("main: "+Thread.currentThread().getName());
t.setName(" CodingAtharva ");
mt = Thread.currentThread(); // main thread
t.start();
t.join();
for(int i =1;i<=10;i++)
{
System.out.println("main: "+Thread.currentThread().getName());
}
}
}
{
static Thread mt = null; // Main Thread
@Override
public void run()
{
System.out.println("run: "+Thread.currentThread().getName());
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();
System.out.println("main: "+Thread.currentThread().getName());
t.setName(" CodingAtharva ");
mt = Thread.currentThread(); // main thread
t.start();
t.join();
for(int i =1;i<=10;i++)
{
System.out.println("main: "+Thread.currentThread().getName());
}
}
}