Difference between process and thread in java is the mostly asked interview question during job interviews. We have discussed about Process and Thread in last article. I am presenting here most of the differences between thread and process. This difference will help you understanding the topic more precisely. Thread vs Process will be discussed below.
Here is the image which shows how process and threads look like inside the computer. You can see multiple threads can be present in a single process. Threads have their own thread control block and share the address space of the main process.
Here is the difference between Process and Thread
[vc_row][vc_column width=”2/3″][td_block_text_with_title custom_title=”Process vs Thread”][/td_block_text_with_title][/vc_column][/vc_row]
|Basic||Process is an instance of a program in execution||Thread is a part of a process|
|Address Space||Process has it own address space||Threads share same address space of a process|
|Control Block||Process has its own Process Control Block (PCB). Process has global variables, child processes, signal handlers, accounting information and open files.||Threads have their own Thread Control Block. Which has a Program Counter, Stack Pointer, Registers.|
|About||Process can have multiple threads||Thread is a small entity which can execute in parallel with other threads|
|Weight||Process is heavy weight||Thread is a light weight process|
|Overhead||Process has a heavy overhead||Thread has a less overhead|
|Dependency||Processes are independent with each other||Threads share the same address space so they are not independent|
|Synchronization||Synchronization is not required||Synchronization can be done in threads|
|Communication||Process communicate with other processes using interprocess communication which is difficult.||Communication between threads can be done very easily because they share same address space|
|Starting New||Starting a new process is different||Start a new thread is simple and it can be done calling new Thread method|
|Context Switching||Context switching between processes is costly||Context switching between threads is less expensive|
[vc_row][vc_column width=”2/3″][td_block_text_with_title custom_title=”Definition”][/td_block_text_with_title][/vc_column][/vc_row]
Process is the instance of a program execution. For example, if you open two windows of a internet browser then you have two processes. It contains the program code and its activity. Process provides an execution environment for our program.
Lightweight processes are called threads. Creating a new thread needs fewer resources than creating a new process. Similar to processes, a thread provides an execution environment for our program.