Wednesday 25 June 2014

Program to print delayed output using multithreading


public class loading implements Runnable{


public void run() {
// TODO Auto-generated method stub
int i;

for(i=0; i<=5; i++)
{
try
{

Thread.sleep(1000);

}
catch(Exception e){}
System.out.println("i="+i);
}

}
public static void main(String[] args)
{
loading l=new loading();
Thread t=new Thread(l);
t.start();

}}

output:
i=0
i=1
i=2
i=3
i=4
i=5

No comments:

Post a Comment

SAY HELLO!!