Difference Process Thread Program

Difference Process Thread Program

Difference Process Thread Program

Summary: It is very confusing for a novice the difference between a Process, Thread and Program. These concepts are explained in simple words in this tutorial "Difference Process Thread Program".

Difference Process Thread Program

A Program when started execution is known as Process. Or to say, a program under execution is known as Process (some people call it as a task). Process occupies some memory space for execution. OS gives a unique process identifier, known as PID, for each process.

A program can be divided into a number of threads. Each thread comprises of a block of statements. A thread also requires some memory space for execution, but the space is allotted within the memory space of the process. If 100 threads exist, all 100 threads takes their execution space within the process memory space (share the process memory space) only. It can be said, a thread is a sub-process or a small process within a process. Each thread have its own stack, registers and counter in Java.

Because all threads of the process executes within the same memory space (of process), their execution is faster. A programmer can shift the control between the threads of the same process and is known as lightweight process. Similarly, there may be another process with threads. If the execution control is shifted between the threads of different processes, it is known as heavyweight process. Obviously, lightweight threads are faster than heavyweight and for this reason, the threads are designed mostly as lightweight by the Programmer.

All threads within a process executes independent of each other. If required, threads can communicate with other (inter process communication) in Java, with wait() and notify() etc.

For Example and more Explanation with Figures, refer

1. What is Thread in Java? Why threads required?

2 thoughts on “Difference Process Thread Program

  1. SPG

    Sir can a thread access another thread..?
    If there is a threadA which is in sleep state and another thread threadB and threadB try to access threadA wht will happen..??

Leave a Reply

Your email address will not be published. Required fields are marked *