The following notes will talk to some of the Java source code. We chose jdk8 track.
If we follow the source, the best choice jdk8, jdk11, because they are long-term support version of Oracle.
The origin of processes and threads, see the following diagram:
the process is the smallest unit of resource allocation, the thread is the smallest unit of CPU scheduling
- All resources associated with the process, are recorded in the PCB (process control block)
- Scheduling process is to seize the processor unit; threads belonging to a process and to share its resources
- Only the thread stack registers, program counter, and TCP (Thread Control Block) composed of
Processes and threads difference:
- Thread can not be seen as a standalone application, and the process can be seen as a standalone application
- Processes have separate address space, not affect each other, just different execution paths threading process
- Thread does not have a separate address space, programs and more robust than the process of multi-threaded programs
- Switching process larger than thread switching overhead
Java processes and threads of relationship:
- Java function provided by the operating system package, including processes and threads
- Run a program will produce a process, the process includes at least one thread
- Each process corresponds to a JVM instance, multiple threads share the JVM heap
- Single-threaded Java programming model, the program will be self-created main thread
- The main thread can create a sub-thread, in principle, to be completed after the child thread execution