88 Program on sleep() of java.lang.Thread in Java?

Code :

public class Test  extends Thread
{
@Override
public void run()
{
try
{

System.out.println("run: "+Thread.currentThread().getName());
Thread.sleep(1000);
}
catch(InterruptedException e)
{
System.out.println( e.toString() );
}
}


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

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




Output:


Previous
Next Post »