Program 27
Program 27
try
{
Thread.sleep(2000);
}
catch(InterruptedException e)
{
System.out.println("Exception Occurred.");
}
}
}
else
{
for(int i=1;i<=5;i++)
{
System.out.println("Thread2");
try
{
Thread.sleep(4000);
}
catch(InterruptedException e)
{
System.out.println("Exception Occurred.");
}
}
}
}
}
t1.start();
t2.start();
}
}
Output:
Thread1
Thread2
Thread1
Thread2
Thread1
Thread1
Thread2
Thread1
Thread2
Thread2