I see a lot of people here confused by what exactly thread priority does, and here's my own explanation. Thread priority only hints to the underlying OS Task Scheduler as to which threads should have more resources allocated to them. It in no way guarantees the order of execution in any way, shape or form. Some OS's may flat out ignore thread priorities. In most textbooks, they will recommend against using thread priorities in any functional ways, and most concurrent applications tend to use the default priority for all threads. I cannot really think of any situation where it would really be necessary to use thread priorities. Telusko is likely introducing thread priority since it is one of the main properties of threads mentioned by Oracle in their examples, and is good knowledge to know about.
Sir please try to explain in easy way we can understand some part but at some point we get confused. Try to teach from basic level it will help us learn easily.thankyou sir.
Hi Naveen Sir, Great Tutorials and Motivation as well... One request Sir, Kindly Do some videos on Data Structures in Java without using Collection classes and kindly teach some Problem Solving Skills I.e competitive programming.. Hope A subscribers request is Heard... Thank You !!
I think, you have explained only the syntax of thread priority. Could you please make part 2 of this video which explains the need of the concept of thread priority with an example
You explained all the methods very nicely but you did not explain the use of thread priority so please make a video on the use of thread priority like how it impacts the threads.
There is a one second sleep in each thread. That is the reason, you are not seeing that thread t2 being run before t1. When a thread sleeps, it is giving up cpu to lower priority thread. Naveen should have removed that sleep call.
First of all we need to know there will be a scheduler - which pick up the thread and execute it , but when there is a collision between the threads, then as we have set priority to hello as 10, hello will be printed then .Thread priority is useful only when there is a collision and we want to execute a particular thread only... But in this example, we have started hi thread before hello and no collision between hi and hello thread because we are using sleep method to avoid collision... So no effect of thread priority is seen.
Navin, When we prioritize things in daily life, we say that things with higher priority are more urgent and should be tended to more urgently. So, why isnt it the same in Threads, even though you said t2 has a higher priority, we still get the same output as before. Arent we telling the compiler that we need to run t2 with greater urgency? So shouldnt we be getting hello several more times than hi? So shouldnt the output look something like hello, hello, hello, hi, hello, hello, hi, hi, hi, hi
Do priority only sets a number to thread??? I cannot see any differences in output but by assigning different priority i was expecting some change in sequence of printing Hi, Hello.
There is a problem with this example. He has a sleep in each thread. That is giving cpu resources to lower priority thread. You should check it out by removing sleep in each thread.
If your cpu is completely filled and it doesn't have the resources to run both of the threads at the same time. It will first run the one with the highest priority.
You're suggesting as if the default priority of every thread is 5. BUT DEFAULT PRIORITY OF EVERY THREAD IS THE PRIORITY OF PARENT THREAD. main thread has priority=5.
Hey I like the way you explain. Can you make a tutorial for a complete WEB Application based on SPRING MVC? Maybe something like maintaining Employee Data or School Data. It would be really helpful.
what happened by changing the priority of threads t1 as 1 priority and t2 as 10 priority ? means what is the effect of changing the priorities of the threads?
The first time for me that i'll press DISLIKE button, because u didn't exaplain what is the purpose of priortize the threads. u should give a real scenario.
@@divineuttrakhand376 no it's not, there's not change in order of execution. This is something different and a programming context would mean something entirely different as well. Don't just assume, technicality is a different world.
I see a lot of people here confused by what exactly thread priority does, and here's my own explanation. Thread priority only hints to the underlying OS Task Scheduler as to which threads should have more resources allocated to them. It in no way guarantees the order of execution in any way, shape or form. Some OS's may flat out ignore thread priorities. In most textbooks, they will recommend against using thread priorities in any functional ways, and most concurrent applications tend to use the default priority for all threads. I cannot really think of any situation where it would really be necessary to use thread priorities. Telusko is likely introducing thread priority since it is one of the main properties of threads mentioned by Oracle in their examples, and is good knowledge to know about.
I expect this kind of excellence in a tutor. Crisp concepts and clear explanation. I paused the flow to give this feedback. Amazing!!
Hi Sir, Can you please explain what is the significance of priority. How it is going to impact the output if we set priority.
Sir please try to explain in easy way we can understand some part but at some point we get confused. Try to teach from basic level it will help us learn easily.thankyou sir.
Hi Naveen Sir, Great Tutorials and Motivation as well... One request Sir, Kindly Do some videos on Data Structures in Java without using Collection classes and kindly teach some Problem Solving Skills I.e competitive programming.. Hope A subscribers request is Heard... Thank You !!
Hi Navin, Good video again! but you did not talk about the use of thread priority. How can use priority to impact the behavior of a thread?
As I observed it depends on jvm which thread is selected, so setting priority doesn't make any difference
I think, you have explained only the syntax of thread priority.
Could you please make part 2 of this video which explains the need of the concept of thread priority with an example
You explained all the methods very nicely but you did not explain the use of thread priority so please make a video on the use of thread priority like how it impacts the threads.
Sir,we have assigned max priority to second thread so why isn't "hello" printing first?
@@midoshbrown4142 That's helpful!
There is a one second sleep in each thread. That is the reason, you are not seeing that thread t2 being run before t1. When a thread sleeps, it is giving up cpu to lower priority thread. Naveen should have removed that sleep call.
@@channamalleshhiremath6320 thank you so much for clearing the doubt brother.
First of all we need to know there will be a scheduler - which pick up the thread and execute it , but when there is a collision between the threads, then as we have set priority to hello as 10, hello will be printed then .Thread priority is useful only when there is a collision and we want to execute a particular thread only... But in this example, we have started hi thread before hello and no collision between hi and hello thread because we are using sleep method to avoid collision... So no effect of thread priority is seen.
@@channamalleshhiremath6320 even if u remove that 2nd sleep u still get random output
Navin, When we prioritize things in daily life, we say that things with higher priority are more urgent and should be tended to more urgently. So, why isnt it the same in Threads, even though you said t2 has a higher priority, we still get the same output as before. Arent we telling the compiler that we need to run t2 with greater urgency? So shouldnt we be getting hello several more times than hi? So shouldnt the output look something like hello, hello, hello, hi, hello, hello, hi, hi, hi, hi
As I observed it depends on jvm which thread is selected, so setting priority doesn't make any difference
Just Awesome.. I was not knowing multithreading was so easy before.
Do priority only sets a number to thread??? I cannot see any differences in output but by assigning different priority i was expecting some change in sequence of printing Hi, Hello.
what is the benefit of assigning priority to a thread in the FirstPlace??
Hi Naveen,
What is the benefit of defining the thread priority, when they are still printing in same order?
There is a problem with this example. He has a sleep in each thread. That is giving cpu resources to lower priority thread. You should check it out by removing sleep in each thread.
what difference it makes ...?
what is the use of priority if nothing is changing
Sir,where i can get the Thread.class so i can see it ?
Sir what is the use of setting priority in thread
If your cpu is completely filled and it doesn't have the resources to run both of the threads at the same time. It will first run the one with the highest priority.
helo sir what is the use of setting priority in thread
What does high or low priority does?
You're suggesting as if the default priority of every thread is 5. BUT DEFAULT PRIORITY OF EVERY THREAD IS THE PRIORITY OF PARENT THREAD. main thread has priority=5.
Hey I like the way you explain. Can you make a tutorial for a complete WEB Application based on SPRING MVC? Maybe something like maintaining Employee Data or School Data. It would be really helpful.
is that war going on in background lot of firing
What is the output for change of priority?
Priority does not create any impact in thread processing????
It may or may not, it just requests cpu to process higher priority thread first but cpu will process them in most efficient way possible.
what happened by changing the priority of threads t1 as 1 priority and t2 as 10 priority ?
means what is the effect of changing the priorities of the threads?
High Priority threads get more CPU Time.
Hi bro
Learning java in 2020 is best or not best ?
But, what is priority?¿?¿?¿?
how to make duplicate fie using multithreading
hlo sir I need some scenario to work out
Purpose of Pirority
what was that clapping noise
00:33 someone get shot?
please be respectful
The first time for me that i'll press DISLIKE button, because u didn't exaplain what is the purpose of priortize the threads. u should give a real scenario.
This is very much understandable that why priority is used even in normal life too.
@@divineuttrakhand376 no it's not, there's not change in order of execution. This is something different and a programming context would mean something entirely different as well. Don't just assume, technicality is a different world.
i love u