CodesJava

Easy learning with example program codes

Difference between process and thread in java?


Multiprocessing:

Multiprocessing is a type of multitasking based upon processes i.e. context switching is done in-between processes. For example: Typing in notepad, Listening music and downloading file from internet at the same time. Here in example we can clearly see that all applications are independent. Multiprocessing is the type of multitasking which is handled at operating system level.

Process:

A process has a self-contained execution environment i.e. allocates separate memory area. Context switch time is more in case of processes because switch is done between different memory areas.

Multithreading:

Multithreading is a type of multitasking based upon threads i.e. context switching is done in-between threads. In case of multithreading, multiple independent tasks are executed simultaneously. These independent tasks are the part of same application. Multithreading is the type of multitasking which is handled at program level.

Thread:

A thread is a lightweight process. Thread uses process’s execution environment i.e. memory area. Context switch time is less in case of threads because switch is done within the same process’s memory area.

A thread represents a flow of execution. Every thread has a job associated with it.

Note: A thread can’t be exist without process, it exist within the process.

Difference between process and thread in java:

                       Process                          Thread
  1. Process has its own main memory for execution.
  2. Process is considered as heavyweight component.
  3. One process can have multiple threads.
  4. Context switch time is more.
  1. Thread use process’s main memory for execution and share it with other threads.
  2. Thread is considered as lightweight component.
  3. One thread can’t have multiple process.
  4. Context switch time is less.

 

Java interview questions on multithreading

Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki