06-04-2011, 01:21 PM
Code:
class A extends Thread
{
public void run()
{
try
{
for(int i=0;i<=15;i++)
{
System.out.println("In thread A\t"+i);
if(i==10)
sleep(100);
}
}
catch(Exception e)
{
System.out.println("Exception"+e);
}
}
}
class B extends Thread
{
public void run()
{
for(int j=0;j<=15;j++)
{
System.out.println("In thread B\t"+j);
if(j==0) yield();
}
}
}
class C extends Thread
{
public void run()
{
for(int k=0;k<=15;k++)
{
System.out.println("In thread C\t"+k);
if(k==10) stop();
}
}
}
class Multthread
{
public static void main(String arg[])
{
A obj1=new A();
B obj2=new B();
C obj3=new C();
obj1.start();
obj2.start();
obj3.start();
}
}
OUTPUT
E:\3msc\java\liya>java Multthread
In thread B 0
In thread A 0
In thread C 0
In thread B 1
In thread A 1
In thread C 1
In thread B 2
In thread A 2
In thread C 2
In thread B 3
In thread A 3
In thread C 3
In thread B 4
In thread A 4
In thread C 4
In thread B 5
In thread A 5
In thread C 5
In thread B 6
In thread A 6
In thread C 6
In thread B 7
In thread A 7
In thread C 7
In thread B 8
In thread A 8
In thread C 8
In thread B 9
In thread A 9
In thread C 9
In thread B 10
In thread A 10
In thread C 10
In thread B 11
In thread B 12
In thread B 13
In thread B 14
In thread B 15
In thread A 11
In thread A 12
In thread A 13
In thread A 14
In thread A 15