In this article, we are going to discuss Multithreading in Java and types.
- What is the thread
- Process-based Multitasking (Multiprocessing)
- Thread-based Multitasking (Multithreading)
In java, Multithreading means multiple threads executing simultaneously in a process is called Multithreading.
By definition, multitasking is when multiple processes share common processing resources such as a CPU.
What is the thread?
A thread is a sub-process of a process. When a big process is divided into multiple small processes, then that small process is called a thread.
Executing multiple tasks simultaneously is called Multitasking. We use multitasking to utilize the CPU.
There are two types of multitasking.
- Process-based Multitasking
- Thread-based Multitasking
Process-based Multitasking (Multiprocessing)
Executing multiple tasks simultaneously, where each task is a separate independent process is called Process-based multitasking.
Each process has an address in memory. In other words, each process allocates a separate memory area.
While a user typing a java programming in the editor, he can able to listing audio songs by an MP3 player in the system, and at the same time, he can also downloading movies file from the internet. So all these tasks are executing simultaneously and independently of each other.n That why this process is called Process-based Multitasking.
Process-based Multitasking is best suitable at the O.S level.
Thread-based Multitasking (Multithreading)
Executing multiple tasks simultaneously, where each task is a separate independent part of the same program is called Thread-based Multitasking.
Thread-based Multitasking is the best suitable for the programming level.
The main objective of Multitasking is to improve the performance of the system by reducing response time.
Read More topics related to the collection.
- Comparable and Comparator in Java
- Java Set Interface
- Java Vector
- Cursors in Java
- Collection Interface
- Collections in java
Read more topics related to java
- Classloader in java
- Inter thread communication in java
- synchronization in java
- Exception in java
- Inner class in java
- Object-Oriented Programming (OOPS) concepts in Java
Hope this was helpful for you. If you have any questions please feel free to leave a comment. Thank you for reading.