From what I can gather, the following code is supposed to execute each thread in a random order and different each time. For me the output is as if I'm not threading at all. First prints 5 times, second prints 5 times, third prints 5 times. I can't see anything wrong with the code.
// second program to demonstrate creation of thread by extenting thread class class First extends Thread{ // FirstThread extended from java.lang.Thread public void run(){ // run method of class for(int i =1 ; i <=5; i++){ // when run, cycle 5 times System.out.println("First Thread is running."); } } } class Second extends Thread{ // second thread public void run(){ // run method of class for(int j = 1; j <=5; j++){ // run 5 times System.out.println("Second Thread is running."); } } } class Third extends Thread{ // third thread public void run(){ // run method of class for(int k = 1; k<=5; k++){ // run 5 times System.out.println("Third Thread is running."); } } } public class ThreadCreateExtend2{ public static void main(String args[]){ First f1 = new First(); // create object of First named "f1" f1.start(); // call start() method inherited from thread class Second s1 = new Second(); s1.start(); Third t1 = new Third(); t1.start(); } }