Multithreading refers to the process of executing multiple threads simultaneously.
A thread can be considered as a smaller unit of processing.
Both multithreading and multiprocessing can be used to achieve multitasking. But in multithreading, threads use shared memory and context switching takes very less time.
Multithreading is mostly used in applications related to games and animations.
A thread can be considered as a smaller unit of processing.
Both multithreading and multiprocessing can be used to achieve multitasking. But in multithreading, threads use shared memory and context switching takes very less time.
Multithreading is mostly used in applications related to games and animations.
Advantages of Multithreading :
- If any exception occurs in a thread then it doesn't block the other threads or tasks from execution.
- Multiple tasks can be executed in parallel so it saves time.
- It doesn't block the user to wait for a particular task to complete as threads are independent of each other.
In Java we can create a thread in two ways...