class joinExp extends Thread
{
public void run()
{
for(int i=1;i<=5;i++)
{
try
{
Thread.sleep(500);
}
catch(Exception e)
{
System.out.println(e);
}
System.out.println(i);
}
}
public static void main(String surat[])
{
joinExp t1=new joinExp();
joinExp t2=new joinExp();
joinExp t3=new joinExp();
t1.start();
try
{
t1.join();
}
catch(Exception e)
{
System.out.println(e);
}
t2.start();
t3.start();
}
}
Output:
{
public void run()
{
for(int i=1;i<=5;i++)
{
try
{
Thread.sleep(500);
}
catch(Exception e)
{
System.out.println(e);
}
System.out.println(i);
}
}
public static void main(String surat[])
{
joinExp t1=new joinExp();
joinExp t2=new joinExp();
joinExp t3=new joinExp();
t1.start();
try
{
t1.join();
}
catch(Exception e)
{
System.out.println(e);
}
t2.start();
t3.start();
}
}
Output:
No comments:
Post a Comment