Multithreading (based on Bi Xiangdong video)

Source: Internet
Author: User

Process: is an executing program
Each process execution has an execution order, which is an execution path, or a control unit.

Thread: is a separate control unit in the process.
The thread is controlling the execution of the process.

There is at least one thread in a process.

A Java Virtual machine will start with a process Java.exe

At least one thread in the process is responsible for the execution of the Java program.
And the code that this thread runs on is in the main method.
This thread is called the primary thread.

Extension: In fact, more details indicate that JVM,JVM started more than one thread, as well as a thread responsible for the garbage collection mechanism.

1, how to customize a thread in code?

By looking at the API, Java has provided a description of things like the county seat. is the thread class.

The first way to create a thread is to inherit the thread class
Steps:
1. Define class inheritance Thread
2. The Run method in the replication thread class
3. Call the thread's Start method
Start action: Starts the thread and calls the Run method.

At some point, there can only be one program running. (except multicore)

The CPU is doing a quick switchover and has reached the effect that it looks like it is running at the same time.
We can image the multi-threaded operation described as in each other to rob the CPU execution right.
This is a feature of multithreading: Randomness.
Who grabs who to execute. Execution time CPU decision.

Multithreading (based on Bi Xiangdong video)

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.