(i) Basic concepts of threads:
(1) Processes and Threads:
Process: Running applications are called processes, owning system resources (CPU, memory)
Thread: A piece of code in a process that can have more than one piece of code in a process. does not own resources (shares the resources of the process in which it resides)
(2) Distinguishing between processes and threads:
1. The question of whether or not to occupy resources
2. The overhead required to create or undo a process is greater than the overhead required to create or undo a thread.
3, the process is a heavyweight component, the thread is a lightweight component
(3) Multiple threads and multiple processes:
Multi-process: multiple tasks (Programs) can be run at the same time in the operating system.
Multithreading: Multiple function flows are executed simultaneously in the same application.
(4) The purpose of the thread:
①, use it to do repetitive work (such as animation, sound playback).
②, engaged in one-time more time-consuming initialization work (such as network connectivity, sound data file loading).
③, concurrent execution of a running effect (multiple threads of a process) for more complex functionality.
(5) The advantages of multithreading:
① can reduce the bottleneck of system performance, because it can be operated in parallel;
②, to improve the efficiency of CPU processor, in multiple threads, through the priority management, can make important program priority operation, improve the flexibility of task management; On the other hand, in a multi-CPU system, different threads can be executed in different CPUs, and multitasking is really handled simultaneously.
(6) The main characteristics of the thread:
1) can not be in a file name independent of the existence of the disk;
2) can not be carried out alone, only after the process has started to start;
3 The thread can share the same memory (code and data) of the process.
(7) The priority of the thread:
Each Java thread has a priority, which helps the operating system determine the scheduling order of the threads. The Java priority is within the range of min_priority (1) and max_priority (10). By default, each thread assigns a priority norm_priority (5).
(ii) Life cycle/state transition diagram for Java threads: