Multi-threading is a thread-based multitasking approach where multiple threads share the same memory address space within a single process, allowing for efficient context switching and lower memory consumption compared to multi-processing. Threads can be created in Java by either extending the Thread class or implementing the Runnable interface, and when a thread is started, it executes the run() method by default.
Deep Dive
Voraussetzung
- Keine Daten verfügbar.
Nächste Schritte
- Keine Daten verfügbar.
Deep Dive
MultiThreading Day 47 By KishanHinzugefügt:
right good evening everyone can you hear me can you see this thing can you please respond in the chat please respond in the chat guys yes yes yes yes yes yes yes yes very very good winning guys very very funny all right so you can email you can see the screen all right so let us start our session again today so guys before starting our sessions as always let us try to have a very very small and a quick recap of the concepts which we had covered in our last class right as a matter of fact guys from last nearly one week to eight days I mean eight to nine days onwards we have been discussing about oops features like object oriented programming features so we have seen first we had this I mean gone through with what is the difference between what is the difference between object oriented programming model languages and procedure oriented programming languages after that we had gone through what is actually encapsulation inheritance polymorphism and abstraction so actually by yesterday we have completed discussing about oops features so guys again I'm saying kindly please concentrate more on oops features okay for example today morning today morning by 7 30 I got this mail guys still I did not uploaded this in the Instagram I'll be uploading this today morning today morning uh when nine o'clock sorry today morning nine o'clock I got this mail from one of my students my name is tejasree seriously and she got placed in Infosys with a package of 3.6 lakhs per annum system engineer role right system engineer as simple as this and if You observe If You observe the questions which she has faced self interaction she's actually as I told you like she's from a non-it background non-80 background okay so she's from civil engineering so why you came to like why you have chosen software industry instead of civil engineering which programming languages do you know she said c in Java what is oops and features of oops what is inheritance difference between multi-level and hierarchical inheritance some questions are related to abstraction can you answer these questions guys can you answer these questions and uh like questions related about like questions about arrays and pointers why this pointers concept came you know like as she said c and Java they have asked questions related to pointers and they asked one more question like whether pointers I mean say something about pointers in Java do we have pointers in Java guys do we have pointers in Java no we don't have any pointers right so that's exactly what she said pointers are not there in Java but I mean after saying that this is his answer he asked that question just to confuse that's it but come on you guys are my students how you'll be getting confused guys right so after that why Java is platform independent what is finally keyword we'll be discussing about that finally keyword whenever we are dealing with whenever we are dealing with exception handling like after completion of this multi-thurning we'll be discussing about exception learning at that particular time we'll be discussing about what is this finally keyword and questions are related to interface find your project do you have a laptop do you have any questions to ask that's it simple questions very very simple questions now in these 14 questions which she has faced nearly five to six questions are related to oops I'm a right or wrong guys one two three four five nearly right so that much important oops concepts are so I'm requesting you guys kindly please do more focus on hopes features can you do that for me please please respond in the chat guys please respond in the chat gunshot cushions gunshot questions you will get these questions so kindly please don't do any mistakes guys please I'm requesting you okay all right all right now let us start our today's session okay now today we are going to start discussing about multi-threading multi-threading okay guys before starting the concept of multi-threading let me try to tell you one important point the one the very first important point which you need to remember in multi-threading is in Threads we cannot guess the output as simple as this okay once again I am saying you once again I am saying you in Threads we cannot guess the output what is the meaning of this particular point just wait for one day I'm not asking you what just wait for one day okay just remember this point what I am trying to say is in trips we cannot guess the output just remember that particular Point okay now now okay before going to this multi-threading first we should be having an idea about multi tasking what is actually multitasking right multitasking means performing multiple tasks by a single processor in order to optimize the utilization of CPU performing multiple tasks at the same time at the same time by a single processor in order to optimize the utilization of CPU foreign means multitask means performing multiple tasks at the same time at the same time by a single processor in order to optimize the utilization of CPU this is known as multitasking guys the best example for multitasking is for example if you take me I'll be trying to like when I'm whenever I am writing my project like whenever I'm trying to write my code I'll be listening to music and I will write the code can you tell me an example like this did you ever perform multitasking videos yeah give me an example give me an example give an example music and studying yes that is good writing assignments in engineering how that is multitasking here how writing records okay music and games listening to music playing chess while chatting oh that is great that is great driving car walking and talking listening and watching thinking in your class yeah of course watching movie and eating popcorn yes yes yes yes all these are all these are multitasking amenity or wrong guys exactly exactly so you got an idea about what is actually multitasking right multitasking means multitasking means performing multiple tasks at the same time by a single processor in order to optimize the utilization of CPU now when you are speaking about this multitasking when you're speaking about this multitasking in Java we can achieve this multitasking by 2s multi processing by using multi-procing or else let me try to write process based multitasking we can achieve we can achieve multitasking in Java into this first one is process based multitasking second one is thread based multitasking process based and multitasking second one is thread base or multitasking process based or multitasking second one is thread base and multitasking process based multitasking is process based multitasking is most commonly known as multi processing process based multitasking is most commonly known as multi-processing and thread based multitasking is most commonly known as most commonly known as multi threading multi-threading as simple as this not more than that process spacer multitasking and thread based multitasking now what is the difference between what is the difference between this multi-processing and multi-threading which one is actually benefit for us and why okay guys let me do one thing just please imagine like uh we are having this is an operating system inside the operating system we are having some tasks like task one task two task three you are having three tasks which you need to complete them okay just let me try to have one more like this okay like this now right foreign [Music] right now this is multi-processing just think like this is multi-processing and this is multi-threading guys in multi-threading you'll be having little bit more Theory will be there if you are not understanding the theory correctly you will not be able to understand the code so please be patient and understand the theory guys I hope it's clear for everyone is it clear guys please respond please respond yes yes very good very good so right now what I'm trying to say is just imagine this is an operating system in this operating system we are having three tasks you need to perform like task one task two task three this is an example for multi-processing this is an example for multi-threading like here also we are having an operating system and here also we are having three tasks three tasks okay now what I want to do you know I want to perform [Music] multi-tasking by using multi-processing Okay Pro CSS process one this is process one let me do one thing let me write P1 okay this is process one this is process one in the same manner P2 this is process two process 2 in the same manner P3 p 3 like this now this is process three this is process three okay now what I want to say here is process one is responsible for completing task one process two is responsible for completing task two and process three is responsible for completing task three now just imagine process one is having an address location like for one I mean four one two like this process 2 is having an address location like 752 process three is having address location like six five four so what I want to conclude is guys in order to complete three tasks how many process we need in order to complete three tasks by using multi-processing how many process we need three process each process is having its own unique address location am I right or wrong guys process one is having four one two processor 2 is having 752 and process 3 is having six five four unique address location okay so this is actually multi-processing so when you are speaking about multi-processing when you are thinking about multiprocessing we can perform different different tasks we can achieve different different tasks by using different different process and obviously each process will be having separate memory I mean entirely a new memory will be there okay now let us come to multi-threading now guys in multi-threading just imagine we are having a process like this okay just a process just let me try to write this is process one okay resist process one now what is the address location of this process one let us take the same address location as let us take the same address location as four one two same address location same address location four one two now inside a process I am speaking inside a process I will be having thread one thread one thread 2 and thread three okay three threads are present in three threads are present in single process I mean in one process one there are three threads are there are simple as this now thread one when you're taking thread one thread one is responsible for completing task one thread 2 is responsible for completing task 2 and thread 3 is responsible for completing task 3.
like this so this is thread one which will be completing task one thread 2 will take care of task two thread 3 will be taking care of foreign guys in multi-processing and multi-threading in multi-processing and in multi-threading which one consumes more memory multi-processing or multi-threading which one consumes more memory guys when you are speaking about multi-processing each process is having its own unique location guys I'm a right or wrong so multi-process will be consuming more memory but when you're speaking about multi-threading threads share same address location one more time I am saying you threads share same address location means inside process one we are having three threads each thread will be taking care of its respective task acid blasters are you understanding me guys please tell me please tell me right now right now if you face a question the question is what is a thread what is a threat and your answer should be Point number one first your answer should be threads share same address locations that is the first point thread sir share same address location Point number two Point number two like I'm trying to give in small small points guys okay this is point number one and point number two point number two process acts as a host for a thread process acts as a post for a thread what do you mean by these guys what do you mean by this process acts as the host for a thread means inside a process only threads will be created if you don't have a process there will not be any threat okay so in order to create a thread inner yes exactly exactly in order to create a thread hundred percent at least one process is required foreign in order to create a thread at least one process is required in order to create a thread at least one process is required yes are you understanding these points guys can you please tell me here when you're speaking about process process is nothing but a simple Java program here simple Java program okay so I'm saying you three points first point is threats share same address location process acts as a host for a thread and in order to create a thread at least one process is required finally last important point is context switching context switching is easy in threads context switching is easy in Threads so what do you mean by context switching guys context switching means shifting from one thread to another thread means already you are executing thread one year you are executing thread one if you want to shift your compiler from thread one to thread two easily you can do that why because all the threads are present in the I mean in this particular example in this particular example thread one thread to thread a thread three all these threads are present in the same address location that is inside a process inside a process I saw you understanding me so if all these threads are present in the same address location easily we can shift our compiler what do you say guys what do you say but when you are speaking about the context switching in multi-processing that is not easy that will take time that will take time okay I hope you're understanding me so right now if anyone asks you what is a thread kindly please do remember to say these points threads shared same address location process acts as a host for a thread in order to create a thread at least one process is required and the context switching is easy in Threads guys up to now is it clear for everyone is clear for everyone please tell me wait for it Krishna you'll understand please wait for it okay that is great that is great guys now now just let me box this right now next concept that is how to create a thread how to just take a small question just like a small question how to create a thread how to create a thread right right now guys again I am saying you threats theory is very very important please I am going literally I'm going very very slow I don't know whether you guys have observed or not theory is very very important in threats why because most of the time most of the time even experienced persons also they will be getting confused in threats but not my students okay so please concentrate correctly concentrate correctly now how to create a thread answer answer we can create a thread in we can create a thread in 2s we can create a thread in two ways guys 2s okay just a second right we can create a thread in 2s first one first one is by extending thread class first one is by extending thread class by extending thread class second one is by implementing first one is by extending thread class second one is by implementing a runnable interface by implementing interface guys did you remember what is actually this runnable interface I told you I told you what is a what is that runnable interface Suma very good runnable interface is a functional interface I told you yes what is actually a functional interface what is actually a functional interface exactly delete exactly yes Krishna Suma yes functional interface will be having only one abstract method will be having only one abstract method yes yes now once again once again guys once again so what I'm trying to say is if we want to create a thread if we want to create a thread we can create a thread into s what are those by extending thread class second one is by implementing a runnable interface by implementing random interface okay okay now now guys I'm going to give a small method just a small method public wired run method public void run method now guys this run method this run method is by default executed by any thread by default executed by any thread if you are if you are starting your thread just starting your thread if you are starting your thread right if you are starting your thread by default that thread should be executing run method run method okay guys every thread here just let me try to write like a small point every thread every thread whenever we are starting a thread starting a thread it will by default execute execute run method by default execute run method so the question is very very simple guys the question is literally very very simple which method will be executed by every thread which method which method public void run method oblique void run method okay every thread whenever we are starting a thread it will execute by default run method like this okay by default it will exert run method now guys thread class I told you we can create a thread into this what are those by using 3D class second one is by using a runnable interface thread class and runnable interface both these are present in both these classes like first one is thread class second one is runnable interface both these class and interface are present in Java Dot Java Dot Lang package both these classes that is thread class thread class and runnable interface both these are present in the Java dot Lang package so whenever we are using thread class or else like a runnable interface no need to import can anyone tell me why no need to import why why no need to import why because already java.lank package is by default imported into every Java program guys yes exactly exactly exactly so no need to import happily we can write our class okay guys now let me try to have a small and quick recap so you know what is actually multitasking so I mean you know actually what is meant by multitasking multitasking means performing multiple tasks at the same time by a single processor in order to optimize the utilization of CPU that is actually multitasking and yes we can perform this multitasking or else we can achieve this multitasking in two ways what are those process based multitasking which is most commonly most popularly known as multi-processing second one is thread based multitasking which most popularly known as multi-threading so we already seen like what is the difference between multi processing and multi-thirding like which one is actually benefit for us and if anyone asks you what is the threat I am requesting you to please say all these four points that would be great okay don't say one or two points I'm requesting you please try to say all these four points after that okay up to now we are saying thread thread and thread yes after that how to create a thread right guys we can create a thread in two ways that is by extending thread class second one is by implementing run level interface and I already told you by default like whenever you are starting a thread whenever you are starting a thread by default it will execute run method it will execute run method that is public void run method yes is it clear for everyone up to now up to now is it clear for everyone is having any doubts guys please feel free to ask me now please please feel free to ask me now if anyone is having any doubts run method is predefined run method is predefined kamalesh okay it is purified method it is predefined Method and the context switching means if we want to shift our compiler from one method to another method instead of saying that I am saying we can switch our compiler from one method to another method so that particular process is known as context switching okay I don't know what is your name let me note 9 Pro okay okay guys you're asking please explain a difference between what difference between difference between multi process and multi-threading I guess right right guys multi-processing simply I'm saying here multi-processing involves multiple process actually process means imagine a program just imagine a program if we want to perform three tasks we need to write three programs if we want to perform three tasks like if we want to achieve three tasks with the help of multi-threading we can create three threads inside one single program no need of writing multiple programs okay data now and now uh Nilesh you're asking why we use functional interface functional interface this runnable is a predefined interface okay the abstract method which is present inside this number interface is public void run method public void run method okay are defined in Java dot Lang package right gaurav you need to think about first thread class okay run method is a method which is present in thread class thread class is present in java.lank package okay gaurav thread class runnable interface these two I mean this is a class this is an interface these are present in java.line package okay right right right so how many threads are present in a process we can create any number of threads guys we can create any number of threads no problem uh so P1 is a single processor no no see uh alpesh all these three process are working in a single system think like that okay runnable interface is also present inside java.lang package only it is also present inside java.lank package only okay right okay run method is always public or private it is always public Ganesh it's a predefined method it's always public okay our thread class and runnable related yes wait for its Summa you need to wait for it please okay yogesh is asking what is life cycle of a thread did I cover that point yogesh please ask the doubt like the concepts which I have already covered I did not cover that life cycle of a thread please wait for it right yes run method is run method is present both For Thread class and runnable no problem Krishna this is a predefined method this is a predefined method okay wait for it wait for it you'll understand wait for it when I was asking if thread came in Java program then it is error exception in thread may like it come now no no see uh when I I'll explain you that just uh please wait for that okay see if a thread is present in your program it is not an error or else not an exception you will be getting exception in thread means where you are getting an exception that is mentioning here whenever you understanding me where you are getting an exception in main thread that is the reason it is mentioning like that it is not like you are not getting an exception because of thread when I okay yes yes yes yeah we cannot take any specific parameters no Ganesh that is performed under method overriding which is more essential multi-processing or multi-threading guys both multi-processing and multi-threading both are used to perform multitasking instead of using the word essential which is more advantage which is more Advantage until multi-threading is Advantage for us both are essential we cannot like say that multi-processing is West no both are needed but in Java point of view multi-threading is having much more advantage okay okay so in which cases we'll be using multi-processing so my in Java mostly we will not be using multiprocessing in Java we will be having multi-threading right so why using multiprocessing mostly wait for it like public private protected no no see run method always should be public run method run method always should be public it is a predefined method it is a predefined method you could not you you will not be able to give any other name it is a predefined method right right all right guys all right all right now do me a favor guys do me a favor I will be giving you this steps I want you to create a thread right now and show me okay what is the meaning of a Constructor what is the exact meaning of a Constructor foreign just follow the steps just follow the steps go ahead go ahead you just go ahead okay in order to start a thread you need to use start method uh Mukesh almost very near but not exactly correct not exactly correct very near but not exactly correct okay okay guys now now please observe here step one step one write a class that extends thread or implements run our interface okay we'll do one thing guys I'll do one thing I'll do one thing I will try to create threads in our tomorrow's class what do you say what is your opinion is it okay foreign is it fine why because uh why because guys like if I want to create everything in a single day this is multi-threading guys this is multi-threading like uh you'll be getting confused I don't want that to be happen is it fine for you see even I also want to do that but uh multi-threading I don't want to complete uh in a like do me a favor just do me a favor up to now whatever the concepts which we have discussed in our today's session just go through them that's it I Like Your Enthusiasm I understand I Like Your Enthusiasm but uh let us try to have a break as of now okay yeah rathod not exactly correct not exactly correct not exactly correct wait for it guys okay all right all right so yes that's it guys that's it for today that's it for today we'll do one thing we'll be trying to continue our sessions again bye tomorrow guys okay thank you guys thank you for listening okay so you're asking how many days it will take to complete this batch uh most probably PSI another below 20 days PSI most probably another below 20 days okay Suma that is great that is good uh not exactly correct but almost near almost near summer almost here anyways we'll be discussing that in our tomorrow's Clause okay all right guys Puja we have already covered that I think you missed that foreign thank you guys thank you for listening thank you we'll be trying to continue our sessions again bye tomorrow thank you
Ähnliche Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 views•2026-06-01











