DEV Community

ChelseaLiu0822
ChelseaLiu0822

Posted on

[Java]Process and Thread

Process: is used to load instructions, manage memory, and manage IO, process can be seen as an instance of the program (program is static, process is dynamic), when a program is running, it will open a process.
Thread: a process can be divided into one to multiple threads, a thread is the instruction flow, and the instruction flow in a certain order to the CPU for execution.

  • In Java, the Thread is the smallest scheduling unit (execution instructions), and the process is the smallest unit of resource allocation (managed resources). In Windows, processes are not active, but only as a container of threads.

  • Processes are independent of each other, while threads exist within the process.

  • Processes have shared resources, such as memory space etc, for their internal threads.

  • Communication between the processes is more complex.

  • Process communication for the same computer is called IPC (inter-process communication).

  • Process communication between different computers, required through the network, and adherence to common protocols such as HTTP.

  • Thread communication is relatively simple because they share memory within processes, and an example is a common variable that multiple threads can access.

  • Threads are lighter, and the cost of thread context switching is generally lower than processes.

Top comments (0)