class A extends Thread
{
public void run()
{
for (int i=1; i<=5;i++)
{
if (i==2)
yield();
System.out.println(this.getName()+" : "+ i);
}
System.out.println("End of child thread : "+this.getName());
}
}
class B extends Thread
{
public void run()
{
for (int j=1; j<=5;j++)
{
System.out.println(this.getName()+" : "+ j);
}
System.out.println("End of child thread : "+this.getName());
}
}
class C extends Thread
{
public void run()
{
for (int k=1; k<=5;k++)
{
System.out.println(this.getName()+" : "+ k);
try
{
sleep(500);
}
catch(InterruptedException e)
{
}
}
System.out.println("End of child thread : "+this.getName());
}
}
class ThreadMethods
{
public static void main(String args[])
{
A threadA=new A();
B threadB=new B();
C threadC=new C();
threadA.setName("Thread A");
threadB.setName("Thread B");
threadC.setName("Thread C");
System.out.println("Start Thread A");
threadA.start();
System.out.println("Start Thread B");
threadB.start();
System.out.println("Start Thread C");
threadC.start();
for (int k=1; k<=5;k++)
{
System.out.println("Main Thread : "+ k);
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
}
}
System.out.println("End of main thread!");
}
}
{
public void run()
{
for (int i=1; i<=5;i++)
{
if (i==2)
yield();
System.out.println(this.getName()+" : "+ i);
}
System.out.println("End of child thread : "+this.getName());
}
}
class B extends Thread
{
public void run()
{
for (int j=1; j<=5;j++)
{
System.out.println(this.getName()+" : "+ j);
}
System.out.println("End of child thread : "+this.getName());
}
}
class C extends Thread
{
public void run()
{
for (int k=1; k<=5;k++)
{
System.out.println(this.getName()+" : "+ k);
try
{
sleep(500);
}
catch(InterruptedException e)
{
}
}
System.out.println("End of child thread : "+this.getName());
}
}
class ThreadMethods
{
public static void main(String args[])
{
A threadA=new A();
B threadB=new B();
C threadC=new C();
threadA.setName("Thread A");
threadB.setName("Thread B");
threadC.setName("Thread C");
System.out.println("Start Thread A");
threadA.start();
System.out.println("Start Thread B");
threadB.start();
System.out.println("Start Thread C");
threadC.start();
for (int k=1; k<=5;k++)
{
System.out.println("Main Thread : "+ k);
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
}
}
System.out.println("End of main thread!");
}
}
0 comments:
Post a Comment