Multithreading at a Glance - Part 1

 

Hello Techie's, How are you all? Hope you are doing well in life. My name is "Sumit Srivastava" and I am MCA passout of 2019 batch. I have taken Multithreading as today's topic. So, let's go.

Multi-threading

Guy's before moving to Multithreading, first we should know about what the Thread is?

A Thread is a lightweight sub-process. It a a smallest part of process which allows to operate any task in a efficient way without interacting to any other thread. It means a thread is independent in nature.

Thread


We can create a thread in two ways:-

1. by extending Thread class

2. by implementing Runnable Interface.


Ex.1 By extending Thread class-

public class Test extends Thread{

        public void run(){

                System.out.println("Thread are in run method by extending thread class");

        }

}


Ex.2 By implementing Runnable Interface-

public class Test implements Runnable{

            public void run(){

                    System.out.println("Thread are in run method by implementing Runnable Interface")

            }

};


Let's now come to Multithreading, as the name suggest -

Multi- multiple

threading- threads

means, a process of executing multiple threads simultaneously(same time) is called as multithreading.


We use multithreading to achieve multitasking.

So the question will come is our mind that what is Multitasking?


Multitasking is nothing but doing multiple task at same time.

Ex:- 

We as a programmer, many of us listen songs on our system while coding, right? it is nothing but doing multitasking, listening songs and doing code at the same time.


Multitasking is of two ways:-

1. process based multitasking

2. thread based multitasking


Let's know about these two-

Process based multitasking

Executing multiple task simultaneously is known as process based multitasking. Here every task is having separate different different independent process.

Ex- While working in our laptop we can perform many task at the same time, like i am writting this article and at same time i am also listening soft music and also i am downloading some stuffs via internet. I am performing these many task in my laptop and all these task is running separately, there is no connection between all these.

It is Developed at OS level.

Process Based Multithreading


 Thread based multitasking

Executing multiple task simultaneously is called thread based multitasking but in case of thread based multithreading every task is having separate independent part of every single process, and that part is thread.

It is developed at program level.

Thread Based Multitasking



to be continued...

So guy's here i am ending up part-1. This article will continue for more detail on this topic. If you like this article then do follow me for further updates.

Keep in touch, happy learning.

Thank You.





Comments

Popular posts from this blog

Aurat- Pyar ka Sagar

Two Best Friends