0% found this document useful (0 votes)
9 views3 pages

Write A Program To Creats Three Threads. "Good Morning","Hello","Welcome"

The document describes a Java program that creates three threads to print the messages "good morning", "hello", and "welcome" alternating every 1, 2, and 3 seconds respectively in an infinite loop. The main method instantiates objects of the three thread classes A, B, and C that extend Thread and start each thread to run concurrently.

Uploaded by

Diksha Kashyap
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)
9 views3 pages

Write A Program To Creats Three Threads. "Good Morning","Hello","Welcome"

The document describes a Java program that creates three threads to print the messages "good morning", "hello", and "welcome" alternating every 1, 2, and 3 seconds respectively in an infinite loop. The main method instantiates objects of the three thread classes A, B, and C that extend Thread and start each thread to run concurrently.

Uploaded by

Diksha Kashyap
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/ 3

WRITE A PROGRAM TO CREATS THREE THREADS.

GOOD MORNING,HELLO,WELCOME.

class A extends Thread


{
synchronized public void run()
{
try
{
while(true)
{
sleep(1000);
System.out.println("good morning");
}
}
catch(Exception e)
{}
}
}
class B extends Thread
{
synchronized public void run()
{
try
{
while(true)
{
sleep(2000);
System.out.println("hello");
}
}
catch(Exception e)
{}
}
}
class C extends Thread
{
synchronized public void run()
{
try
{
while(true)
{
sleep(3000);
System.out.println("welcome");
}
}
catch(Exception e)
{}
}
}
class ThreadDemo
{
public static void main(String args[])
{
A t1=new A();
B t2=new B();
C t3=new C();
t1.start();
t2.start();
t3.start();
}
}

OUTPUT:
good morning
good morning
hello
good morning
welcome
good morning
hello
good morning
welcome
hello
good morning
good morning
hello
good morning
welcome
good morning
hello
good morning
good morning
hello
welcome
good morning

You might also like