There are two ways to implement Java threads:Inherit thread,Runnable.
Package COM. ch. thread; public class threadtest extends thread {public threadtest (string name) {super (name); // todo auto-generated constructor stub} @ overridepublic void run () {// todo auto-generated method stubsuper. run (); For (INT I = 0; I <100; I ++) {system. out. println (this. getname () + "thread running ing,") ;}/ *** @ Param ARGs * @ throws interruptedexception */public static void main (string [] ARGs) throws interruptedexception {// todo auto-generated method stubthreadtest TT = new threadtest ("thread one"); threadtest TT2 = new threadtest ("Thread two"); TT. start (); // TT. join (); tt2.start ();}}
package COM. ch. thread; public class threadimpl implements runnable {@ overridepublic void run () {// todo auto-generated method stubsystem. out. println ("thread running,");}/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stubthreadimpl Ti = new threadimpl (); thread TT = new thread (Ti); TT. start () ;}