Java.lang.Thread Use and summary

Source: Internet
Author: User

1  Public classmainthread{2      Public Static voidMain (String args[]) {3         //The first way to start a thread4Otherthread ot=NewOtherthread ();5Thread t=NewThread (OT);6 T.start ();7         8         //The second way to start a thread9Itemthread it=NewItemthread ();Ten It.start (); One          A          for(inti=0;i<100;i++){ -System.out.println ("Main Thread:------" +i); -         } the     } - } -  - classOtherthreadImplementsrunnable{//implements the Runnable interface, the JDK knows you are a threading class +      Public voidrun () { -          for(inti=0;i<100;i++){ +System.out.println ("Other Thread:" +i); A         } at     } - } -  - classItemthreadextendsthread{ -      Public voidrun () { -          for(inti=0;i<100;i++){ inSystem.out.println ("Item Thread"); -         } to     } +}

Horse Soldier: A thread is a different execution path within a program. It's enough to understand the concept.
Process: Just a static concept, a class file on the machine, an EXE file called a process
In fact, the thread is running, the process is a static concept, the process is not running, and the process is running the main process.
DOS is only supported for single-process, at the same point in time only one process in the execution

Use interface is flexible, can use interface when try not to inherit from thread class

The Run () method ends and the thread ends

Java.lang.Thread Use and summary

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.