87 Program on Java.lang.Thread.join() - Java Thread Join in Java ?

Code :

public class Test  extends Thread
{
@Override
public void run()
{
for(int i =1;i<=10;i++)
System.out.println("run: "+Thread.currentThread().getName());
try
{
Thread.sleep(1000);
}
catch(Exception e)
{
System.out.println( e.toString() );
}
}


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

t.setName(" CodingAtharva ");
t.start();
t.join();

for(int i =1;i<=10;i++)
System.out.println("main: "+Thread.currentThread().getName());
}
}



Output:


Previous
Next Post »