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.
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 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.
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:
Java interview questions on multithreading
- What is multithreading?
- Difference between process and thread in java?
- What is thread in java?
- What is the difference between preemptive scheduling and time slicing?
- What is join method in java?
- What is the difference between sleep and yield method?
- Is it possible to start a thread twice in java?
- Can we call run method directly in java?
- What is daemon threads in java?
- Can we make the user thread as daemon thread if thread is started?
- What is synchronization?
- What is synchronized block in java?
- What is synchronized method in java?
- What is static synchronization in java?
- What is deadlock in java?
- What is starvation in java?