Packagealgorithm;classMythreadextendsthread{String name; PublicMythread (String name) { This. name=name; } Public voidrun () {System.out.println (name+ ": Step1"); SYSTEM.OUT.PRINTLN (Name+ ": Step2"); SYSTEM.OUT.PRINTLN (Name+ ": Step3"); }}classMythread1Implementsrunnable{String name; Mythread1 (String name) { This. name=name; } Public voidrun () {System.out.println (name+ ": Step1"); SYSTEM.OUT.PRINTLN (Name+ ": Step2"); SYSTEM.OUT.PRINTLN (Name+ ": Step3"); }} Public classThread1 { Public Static voidMain (string[] args) {/*Mythread a = new Mythread ("a"); Mythread B = new Mythread ("B"); Mythread C = new Mythread ("C"); A.start (); B.start (); C.start ();*/Mythread1 a=NewMythread1 ("a"); Mythread1 b=NewMythread1 ("B"); Mythread1 C=NewMythread1 ("C"); Thread T1=NewThread (a); Thread T2=NewThread (b); Thread T3=NewThread (c); T1.start (); T2.start (); T3.start (); }}
Java Multithreaded code sample