Because Java classes can only inherit one class to implement multiple interfaces, it is generally not recommended to use the inherited thread class for multi-threading, which is a simple multithreaded code that implements the Runnable interface approach.
Packagetext;/*** Multithreading *@authorAdmin **/ Public classThreads { Public Static voidMain (string[] args) {thread_1 T1=Newthread_1 (); Thread Thread1=NewThread (t1); Thread1.start (); Thread_2 T2=Newthread_2 (); Thread thread2=NewThread (T2); Thread2.start (); }} classThread_1Implementsrunnable{ Public voidrun () {Try { //thread paused for one secondThread.Sleep (1000);//This method is simply added to see the threading effect more directlySystem.out.println ("Execution Method 1"); } Catch(interruptedexception e) {e.printstacktrace (); } }}classThread_2Implementsrunnable{ Public voidrun () {Try{Thread.Sleep (1000); System.out.println ("Execution Method 2"); } Catch(interruptedexception e) {e.printstacktrace (); } } }
Java Multithreading--Implement Runnable interface mode