class ThreadOne extends Thread
{
public void run()
{
try
{
for(int i=1;i<=10;i++)
{
System.out.println("Thread 1 : "+i);
Thread.sleep(500);
}
}
catch(InterruptedException e)
{}
}
}
class ThreadTwo extends Thread
{
public void run()
{
try
{
for(int i=10;i>0;i--)
{
System.out.println("Thread 2 : "+i);
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{}
}
}
class Exp9_2
{
public static void main(String[] args)
{
ThreadOne obj1 = new ThreadOne();
ThreadTwo obj2 = new ThreadTwo();
obj1.start();
obj2.start();
}
}
/* OUTPUT!!!
Thread 1 : 1
Thread 2 : 10
Thread 1 : 2
Thread 1 : 3
Thread 2 : 9
Thread 1 : 4
Thread 1 : 5
Thread 2 : 8
Thread 1 : 6
Thread 1 : 7
Thread 2 : 7
Thread 1 : 8
Thread 1 : 9
Thread 2 : 6
Thread 1 : 10
Thread 2 : 5
Thread 2 : 4
Thread 2 : 3
Thread 2 : 2
Thread 2 : 1
*/
{
public void run()
{
try
{
for(int i=1;i<=10;i++)
{
System.out.println("Thread 1 : "+i);
Thread.sleep(500);
}
}
catch(InterruptedException e)
{}
}
}
class ThreadTwo extends Thread
{
public void run()
{
try
{
for(int i=10;i>0;i--)
{
System.out.println("Thread 2 : "+i);
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{}
}
}
class Exp9_2
{
public static void main(String[] args)
{
ThreadOne obj1 = new ThreadOne();
ThreadTwo obj2 = new ThreadTwo();
obj1.start();
obj2.start();
}
}
/* OUTPUT!!!
Thread 1 : 1
Thread 2 : 10
Thread 1 : 2
Thread 1 : 3
Thread 2 : 9
Thread 1 : 4
Thread 1 : 5
Thread 2 : 8
Thread 1 : 6
Thread 1 : 7
Thread 2 : 7
Thread 1 : 8
Thread 1 : 9
Thread 2 : 6
Thread 1 : 10
Thread 2 : 5
Thread 2 : 4
Thread 2 : 3
Thread 2 : 2
Thread 2 : 1
*/