Program: A static code, a set of ordered sets of instructions, which itself does not have any meaning of running, it is just a static entity, is the application of software implementation of the blueprint.
process: is a dynamic execution of a program, which corresponds to loading from code, execution to completion of a complete process, is a dynamic entity, it has its own life
cycle. It is created because it is scheduled to run, is waiting for a resource or event, and is undone due to completion of the task. Reflects a program in
a certain amount of data all dynamic processes running on the set. A process is uniquely identified by a Process control block (PCB). While the process occupies the appropriate resources (such as a package
CPU-enabled with , the rotation time, and the permissions of some other devices). is a system for resource allocation and scheduling of an independent unit.
The main differences between programs and processes are:
Whether the state has a resource whether it has a unique identity and whether it has concurrency
Process Dynamic There are there are
Program Static No No No
Threads: can be understood as a number of execution threads for a process, each of which corresponds to its own independent life cycle. A thread is an entity of a process that is CPU-dispatched and dispatched
Basic unit, which is a smaller unit that can run independently than a process. One thread can create and revoke another thread, multiple threads in the same process
Room can and implementation.
Here is a detailed explanation of the concepts of processes and threads in Java.
Threads in Java go through 4 processes
1) Create
There are two common ways to create a Java thread:
Inherit the thread class and implement the Runnable interface in two ways.
2) execution
after a thread is created, it only occupies memory resources, and the thread does not yet have it in the JVM-managed thread, which must call the Start method to notify the JVM, so the JVM
would have know that there is another thread waiting in line. If the current thread is CPU-bound, the current thread will continue to execute.
3) Interrupt
A.JVM switches the use of the CPU from the current thread to another thread, leaving this thread out of the CPU's usage rights and in a broken state.
B. The thread calls the sleep method during execution, leaving the current thread in hibernation.
C. The thread calls the wait method during execution
D. A thread performs an action while it is using CPU resources in such a blocking state.
4) Death
The thread of death is not capable of execution. There are two causes of thread death:
A. Death caused by the end of the thread's normal operation, that is, the Run method is executed.
B. The thread was prematurely forced to terminate.
A detailed description of the programs, processes, and threads in Java ...