Write a java program that executes three threads. First thread displays Good Morning everyone second. Second thread displays Hello every two seconds and the third thread displays Welcome in every three seconds. Create the three threads by extending the thread class.
class A extends Thread {
synchronized public void run() {
try {
int i=0;
while (i<5) {
sleep(1000);
System.out.println("Good morning ");
i++;
}
} catch (Exception e) {
}
}
}
class B extends Thread {
synchronized public void run() {
try {
int i=0;
while (i<5) {
sleep(2000);
System.out.println("hello");
i++;
}
} catch (Exception e) {
}
}
}
class C extends Thread {
synchronized public void run() {
try {
int i=0;
while (i<5) {
sleep(3000);
System.out.println("welcome");
i++;
}
} catch (Exception e) {
}
}
}
class Main {
public static void main(String args[]) {
A a = new A();
B b = new B();
C c = new C();
a.start();
b.start();
c.start();
}
}
Comments
Leave a comment