process: Baidu Encyclopedia said "process" is a computer program on a set of data on a running activity, the system is the basic unit of resource allocation and scheduling, is the basis of the operating system structure. "," says Wikipedia, "is the entity that has programs running on the computer. The process itself does not run, it is a container for threads. "
Thread: Baidu Encyclopedia says "threads, sometimes called lightweight processes (lightweight PROCESS,LWP), are the smallest unit of program execution flow," says Wikipedia, "the smallest unit in which the operating system is able to perform operational scheduling." It is contained in the process and is the actual operating unit of the process. ”。
Before we figure out these nouns, let's look at how they are produced.
When the computer was first born, the computer can only accept some specific instructions and execute, when the user input instructions, the computer can only wait, so inefficient, and then people began to think, is not able to write a list of instructions to the computer to execute, so, with the batch processing operating system; But then people found a problem, For example, when a program requires long-time I/O operations, the CPU can only wait for it to read the data, so the efficiency is also relatively low. And then people started to think, is it possible for a program to wait for a resource to be able to let another program run, until the previous program resources are ready to run, the equivalent of not only running a program in memory? Process generated, with a process to correspond to a program, each process corresponding to a certain amount of memory address space, and only with their own, the process does not interfere with each other, at the same time, the process saves the program every moment of the running state, so that the process can be switched between. This makes the user feel like a computer performing multiple tasks at the same time, called "Concurrency." Note: For a single-core CPU, the fact is that only one process consumes the CPU at a time.
Then, people on the real-time requirements of the computer is higher, although it is possible to execute multiple processes, but when a process is executed, a process can only do one thing in a period of time, then it can be cut into multiple sub-tasks, concurrent execution? Then people invented the thread, through the switch between threads, so that users feel the system is doing a lot of things at the same time.
The process makes it possible for the concurrency of the operating system to be made possible by threads that allow intra-process concurrency.
Now look at the above explanation, the process is the basic unit of system resource allocation and dispatch, each process has its own resources; a process can include multiple threads, and a thread is the smallest unit of system operation scheduling, so multiple threads within a process are resources of the shared process.
Of course, the above explanations are related to physical devices, such as whether the CPU is single-core or multi-core.
Here's a picture of the Resource Monitor:
With this diagram, it is straightforward to see that an eclipse process contains multiple threads. Processes and threads are not an object of magnitude, so individuals do not think it is necessary to compare them together, and the relationship between classes and objects is similar.
Java concurrent programming--processes and threads