Friday, August 16, 2013

java Program to Implement Multithreading

Program to Implement Multithreading
import java.lang.*;
class aa extends Thread
{
public void run()
{
for(int i=0;i<4;i++)
{
try
{
if(i == 3)
{
sleep(4000);
}
}
catch(Exception x)
{ }
System.out.println(i);
}
System.out.println(" i finished ");
}
}
class bb extends Thread
{
public void run()
{
for(int i=0; i<4; i++)
{
System.out.println(i);
}
System.out.println(" ii finished ");
}
}

class cc extends Thread
{
public void run()
{
for(int i=0; i<4; i++)
{
System.out.println(i);
}
System.out.println(" iii finished ");
}
}
class multi_thread
{
public static void main(String arg[])
{
aa a1 = new aa();
bb b1 = new bb();
cc c1 = new cc();
a1.start();
b1.start();
c1.start();
}
}

No comments:

Post a Comment