1. Review of traditional threading technology-jdk5 multithreading

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.