Dark Horse Programmer-Learning Diary (multithreading)

Source: Internet
Author: User

Process: The application being executed. The amount of space a memory allocates when an application runs.
Thread: A control unit executed by a program in a process, an execution path. Responsible for the execution order of the program. The meaning of multithreading exists: at least two threads are running in the program, one is the main thread of the primary function and the other is the garbage collection thread. Thread Creation Method One: inherits the thread class. To overwrite its run method, call the threading Start method. function: 1. Start thread 2. Run the running method. The goal is to store the custom code in the Run method, so that the thread runs the CPU one program at a time, but switches between different threads quickly, showing the randomness of multithreading
classMlpcextendsthread //First step, define class inheritance Thread class {Private Static intTicket = 100;  Public voidRun () ///Step two, overwrite the Run method and write the code that needs to be run in the field { while(true)        {            if(ticket>0) {System.out.println (Thread.CurrentThread ()+ "" +ticket--); }        }    }} classMlpcdemo { Public Static voidMain (string[] args) {MLPC M1=NewMLPC (); ///Third step, create a thread object by creating a subclass object of the thread class. mlpc m2=NewMLPC (); MLPC M3=NewMLPC (); MLPC M4=NewMLPC (); M1.start ();        //Fourth step, call the Start method, open the thread, execute the Run method M1.start ();        M1.start ();    M1.start (); }}


The Run method and the Start method Run method is just the object invocation method, and the Start method is not running thread and the run method in the thread is started

Dark Horse Programmer-Learning Diary (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.