Difference between Process and Thread in Java


JavaViews 3007

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.

Process vs Thread in Detail

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]

Based OnProcessThread
BasicProcess is an instance of a program in executionThread is a part of a process
Address SpaceProcess has it own address spaceThreads share same address space of a process
Control BlockProcess 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.
AboutProcess can have multiple threadsThread is a small entity which can execute in parallel with other threads
WeightProcess is heavy weightThread is a light weight process
OverheadProcess has a heavy overheadThread has a less overhead
DependencyProcesses are independent with each otherThreads share the same address space so they are not independent
SynchronizationSynchronization is not requiredSynchronization can be done in threads
CommunicationProcess 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 NewStarting a new process is differentStart a new thread is simple and it can be done calling new Thread method
Context SwitchingContext switching between processes is costlyContext 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

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.

Thread

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.

[vc_row][vc_column width=”2/3″][td_block_text_with_title custom_title=”References”][/td_block_text_with_title][/vc_column][/vc_row]
Reference 1

Translate »