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)