Package learn. thread;/*** use the Thread class to create a thread. The start () method (the run () method is automatically called) and the run () method, * To implement your own thread, rewrite the run () method. * @ author whitetiger **/public class learnone {public static void main (string [] ARGs) {demo = new demo (); demo. start (); // start the thread while (true) {system. out. println (thread. currentthread (). getname () + ">>>> main method") ;}} class demo extends thread {@ overridepublic void run () {While (true) {system. out. println (thread. currentthread (). getname () + "learnone ");}}}
Package learn. thread;/*** to implement the runnable interface, you must implement the run method unless it is an abstract class * declaring new A (); * Call New thread (). start (); * to implement your own thread, rewrite the run () method * @ author whitetiger **/public class learntwo {
Public static void main (string [] ARGs) {demo2 de = new demo2 (); New thread (de ). start (); While (true) {system. out. println (thread. currentthread (). getname () + ">>> main thread ");}}}
Class demo2 implements runnable {
@ Override public void run () {// todo auto-generated method stub while (true) {system. out. println (thread. currentthread (). getname () + "in-thread ");}}}