The process is a program in execution, the program is static (we do not run it after writing to keep it there), the process is the implementation of the program, is a dynamic concept. A process can have multiple threads.
Two. Multithreading contains two or more than two concurrently running parts, which are called threads for each of these concurrently running parts of a program.
1. Process-based multitasking means that you allow your computer to run two or more programs at the same time.
2. Thread-based multitasking means that a program can perform two more tasks.
Three. How Java threads are implemented:
1. Extends Thread and rewrite the Run () method.
2. Implements Runnable interface, pass the object implementing the Runnable interface as a parameter to the new Thread (new Runnable () {public void Run () {}});
Start a thread call the start () method, not the run () method!!!!!! The start () method first prepares the system resources for the execution thread and then calls the run () method of the Runnable interface. When a category inherits the thread or implements the Runnable interface, the class is called a thread class.
Four. Stop a running thread do not use the Stop () method, with a variable to control.
Five. The life cycle of a thread:
1. Create a status: New A Thread class object, the system does not allocate resources;
2. Operational status: Call the Start () method to allocate resources, so that the thread class object has a running condition, if the CPU time slice, then the thread into a running state (everything is ready, only the time slice);
3. Non-operational status: the thread block or time slice is exhausted, the block becomes operational after completion, the time slice runs out and becomes operational again, waiting for the time slice to be allocated again;
4. Extinction status: Thread end;
Java Multithreading Summary