Multithreading Introduction

Multithreading Introduction

In this this tutorial, we are going to discuss about Multithreading Introduction in java. Multithreading is a programming concept that allows multiple threads of execution to run concurrently within a single process. Each thread represents a separate path of execution within the program, capable of performing tasks independently.

Multithreading enables programs to better utilize available CPU resources and improve responsiveness by allowing concurrent execution of tasks.

Multithreading Introduction

Before discussing about multithreading introduction, lets explore on what is multi tasking and how many types of multitasking.

Multitasking

Executing several tasks simultaneously is called ‘Multitasking’, There are 2 types of multitasking.

1. Process based Multitasking

Executing several tasks simultaneously where each task is a separate independent process is called ‘Process based Multitasking’.

E.g

While writing java program in the editor we can run MP3 player. At the same time we can download a file from the net. All these tasks are executing simultaneously and independent of each other. Hence it is process based Multitasking. Process based Multitasking is best suitable at O.S level.

2. Thread based Multitasking

Executing several tasks simultaneously where each task is a separate independent part of the same program is called ‘Thread based Multitasking’. This type of multitasking is best suitable at programmatic level.

Java provides in built support for thread based multitasking by providing rich library (Thread, ThreadGroup, Runnable ..etc)

Whether it is Process based or Thread based the main objective of multitasking is to reduce response time and improve performance of the system. The main application area of multi threading is video games implementation, Multimedia graphics , to develop animations etc.

Multithreading

Threads are the backbone of multithreading. We are living in a real-world which in itself is caught on the web surrounded by lots of applications. With the advancement in technologies we cannot achieve the speed required to run them simultaneously unless we introduce the concept of multi tasking efficiently. It is achieved by the concept of thread. 

In the above example, we come across both multiprocessing and multithreading. These are somehow indirectly used to achieve multitasking. In this way the mechanism of dividing the tasks is called multithreading in which every process or task is called by a thread where a thread is responsible for when to execute, when to stop and how long to be in a waiting state. Hence, a thread is the smallest unit of processing whereas multitasking is a process of executing multiple tasks at a time.

Multitasking is being achieved in two ways:

  1. Multiprocessing: Process-based multitasking is a heavyweight process and occupies different address spaces in memory. Hence, while switching from one process to another, it will require some time be it very small, causing a lag because of switching. This happens as registers will be loaded in memory maps and the list will be updated.
  2. Multithreading: Thread-based multitasking is a lightweight process and occupies the same address space. Hence, while switching cost of communication will be very less.

That’s all about multi threading introduction in Java. If you have any queries or feedback, please write us email at contact@waytoeasylearn.com. Enjoy learning, Enjoy Java..!!

Multithreading Introduction
Scroll to top