Difference between process and thread in Java Multithreading?

(Last Updated On: March 19, 2017)

Answer:Difference between process and thread in java multithreading listed below is applied to all languages i.e. Java, C, C++ and C# etc. Here are 4 major important differences are described.

1)Processes are heavy-weight and threads are light-weight.

  • Heavy –weight: each process shares different virtual address space.
  • Light-weight: each thread shares same virtual space. Means, threads share the address space of the process that created it. But, it  is   important to notice that each thread has its own stack.

2)If a process crashes, it does not affect other processes. But, if one thread crashes, all threads within a process and process itself goes away.

  • As a practice, threads implementation require more attention towards crash prevention, as it is very difficult to find which thread is   getting crashed. But, in case of processes, we can easily find the process that got crashed.

3)Processes have a higher start-up and shutdown cost than threads.

4)Inter-process communication (IPC) is harder and slower than inter-thread communication.

  • We can use vector, queue list and array etc. as a shared memory for communication between threads easily, but, for IPC we need to use serialization/de-serialization, sockets etc., that’s harder.

Notes:

  • You may find more difference between process and thread but, these 4 differences are focus of real time projects. So, in any interview if you are able to explain all these differences your answer will be impressive.
  • Above differences of process and thread are applied to all languages C, C++, C# and Java etc.