0% found this document useful (0 votes)
94 views4 pages

Experiment NO. - 10: AIM - Write A Program in Java Using Thread To Show The Use of Yield, Stop and

The document describes a Java program that uses three thread classes - A, B, and C - to demonstrate the yield, stop, and sleep methods. Class A yields after printing 1, class B stops after printing 3, and class C sleeps for 1000 milliseconds after printing 1. The main method creates and starts instances of the three thread classes to show their output.

Uploaded by

Mamta Bansal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views4 pages

Experiment NO. - 10: AIM - Write A Program in Java Using Thread To Show The Use of Yield, Stop and

The document describes a Java program that uses three thread classes - A, B, and C - to demonstrate the yield, stop, and sleep methods. Class A yields after printing 1, class B stops after printing 3, and class C sleeps for 1000 milliseconds after printing 1. The main method creates and starts instances of the three thread classes to show their output.

Uploaded by

Mamta Bansal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

EXPERIMENT NO.

– 10
AIM – Write a program in Java using Thread to show the use of yield, stop and
sleep methods.

CODE –

class A extends Thread


{
public void run()
{
for (int i=1;i<=5;i++)
{
if(i==1) Thread.yield();
System.out.println("\t From thread A: i= " +i);
}
System.out.println("exit from A ");
}
}

class B extends Thread


{
public void run()
{
for (int j=1;j<=5;j++)
{
System.out.println("\t From thread B: j= " +j);
if(j==3)
stop();
}
System.out.println("exit from B");
}
}

class C extends Thread


{
public void run()
{
for (int k=1;k<=5;k++)
{
System.out.println("\t From thread C: k= " +k);
if(k==1)
{
try
{
sleep(1000);
}
catch(Exception e)
{
}
}
}
System.out.println("exit from C");
}
}
public class ThreadMethods
{
public static void main(String args[])
{
A threadA =new A();B threadB =new
B(); C threadC =new 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();
System.out.println("end of main thread");
}
}
OUTPUT –

You might also like