Java program that creates three threads. The first thread displays "Good Morning" for every one second, the second thread displays "Hello" for every two seconds and third thread displays "Welcome" for every three seconds.


class GoodMorning 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 Hello extends Thread {
	synchronized public void run() {
		try {
			int i=0;
			while (i<5) {
				sleep(2000);
				System.out.println("hello");
				i++;
			}
		} catch (Exception e) {
		}
	}
}

class Welcome extends Thread {
	synchronized public void run() {
		try {
			int i=0;
			while (i<5) {
				sleep(3000);
				System.out.println("welcome");
				i++;
			}
		} catch (Exception e) {
		}
	}
}

class MultithreadDemo {
	public static void main(String args[]) {
		GoodMorning t1 = new GoodMorning();
		Hello t2 = new Hello();
		Welcome t3 = new Welcome();
		t1.start();
		t2.start();
		t3.start();
	
	}
}

 OUTPUT:

Good morning 
Good morning 
hello
welcome
Good morning 
hello
Good morning 
Good morning 
welcome
hello
hello
welcome
hello
welcome
welcome

Detailed OUTPUT with Delays:

Multithreading-java