Chapter 1 multithreading Section 1 notes
1,Program: A staticCode.
Process: a dynamic execution process of a program, which corresponds to a complete process from code loading, execution to execution.
A process is also called a task. an OS that supports simultaneous execution of multiple processes is called
2. In a program, multiple tasks can be concurrently executed, and each task is called a thread.
A thread is a smaller execution unit than a process. It is an independent control flow in a process, that is, the control flow inside the program.
Features: The thread cannot be run independently and must depend on the process to run in the process.
Each program has at least one thread called the main thread.
Single thread: multiline Name:
Advantage: Improves the interface response speed. Make full use of system resources. Disadvantages:
1. inherit from the Thread class.
Java. lang 1> class name extends thread, new object, thread new status, start ()-start thread-thread ready, wait for the object to wait in the ready queue. 2. Put the code of the task completed by the thread in the run () method, and rewrite the run () method.
Thread features: Random. When the system executes a multi-line name
2. Implement the runnable interface // avoids multiple inheritance
Multiple Threads implement the runnable interface to create thread objects. Create a thread object with the object as the parameter and start the thread. Thread object. Start () method start thread wait CPU time slice, sleep () (enter sleep mode) method/Wait () method to let out CPU resources. Wait for the CPU resource to be obtained. Create-start () --> ready-CPU available-> Run-> dead/blocked (BLOCKED)
Thread Java.
3. Use timer and timertask combination. ---->