excerpt from:
Zhang Xiaoxiang podcast, the teacher's "Java High-tech" video, and added a personal summary and understanding. Although I have not attended any training courses, a large part of my knowledge comes from the web-sharing video of the Wisdom Podcast.
very sincere thanks to Mr. Zhang's public video.
1 Importorg.junit.Test;2 /**3 * Traditional Thread review4 * Multithreading does not necessarily improve operational efficiency, and is related to CPU design and architecture. 5 * Multi-threaded download is to rob the resources of the server, not its own machine to speed up. 6 * @authorlitaiqing7 */8 Public classTraditionthread {9 /**Ten * How two traditional threads are created One */ A @Test - Public voidtest1 () { - //Way One theThread thread =NewThread () { - /** - * from the Thread.class source code, the Run method is performed by default Target.run (); - * @Override + Public void Run () { - if (target! = null) { + Target.run (); A } at } - - private Runnable target; - */ - @Override - Public voidrun () { in while(true){ - System.out.println (Thread.CurrentThread (). GetName ()); to //do not use this because this is not valid in the way that runnable creates threads + //System.out.println (This.getname ()); - } the } * }; $ Thread.Start ();Panax Notoginseng /** - * Mode two the * Better use of runnable, more consistent with the idea of object-oriented programming, less coupling of the program structure, separating the task from the host + */ AThread thread2 =NewThread (NewRunnable () { the @Override + Public voidrun () { - while(true){ $ System.out.println (Thread.CurrentThread (). GetName ()); $ //Error - //System.out.println (This.getname ()); - } the } - });Wuyi Thread2.start (); the //------------------------------------- - /** Wu * Consider which piece of code to run back? - */ About NewThread (NewRunnable () { $ @Override - Public voidrun () { - while(true){ - Try { AThread.Sleep (500); +}Catch(interruptedexception e) { the e.printstacktrace (); - } $System.out.println ("runable:" +Thread.CurrentThread (). GetName ()); the } the } the }){ the /** - * Run this code block, the subclass overrides the method of the parent class, then run the subclass first, or find the parent class in */ the @Override the Public voidrun () { About while(true){ the Try { theThread.Sleep (500); the}Catch(interruptedexception e) { + e.printstacktrace (); - } theSystem.out.println ("Run:" +Thread.CurrentThread (). GetName ());Bayi } the } the }.start (); - } -}
1. Review of traditional threading technology-jdk5 multithreading