13.6 Multithreading Thread Priority in Java

Поделиться
HTML-код
  • Опубликовано: 15 ноя 2024

Комментарии • 50

  • @jeffreyluo6621
    @jeffreyluo6621 2 года назад +15

    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.

  • @sangavia6687
    @sangavia6687 2 года назад +1

    I expect this kind of excellence in a tutor. Crisp concepts and clear explanation. I paused the flow to give this feedback. Amazing!!

  • @sailajach7935
    @sailajach7935 4 года назад +14

    Hi Sir, Can you please explain what is the significance of priority. How it is going to impact the output if we set priority.

  • @aishu6653
    @aishu6653 Год назад +1

    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.

  • @Deepak71574
    @Deepak71574 8 лет назад +4

    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 !!

  • @dipak002
    @dipak002 5 лет назад +12

    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?

    • @mohdezazulhaq1654
      @mohdezazulhaq1654 3 года назад +1

      As I observed it depends on jvm which thread is selected, so setting priority doesn't make any difference

  • @KarthikReddy-tkr
    @KarthikReddy-tkr 3 года назад +2

    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

  • @Leo-qo5hk
    @Leo-qo5hk 3 года назад +1

    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.

  • @MadhuriDixitannavazzala
    @MadhuriDixitannavazzala 7 лет назад +26

    Sir,we have assigned max priority to second thread so why isn't "hello" printing first?

    • @raghavddps2
      @raghavddps2 4 года назад

      @@midoshbrown4142 That's helpful!

    • @channamalleshhiremath6320
      @channamalleshhiremath6320 4 года назад +6

      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.

    • @bittooaggarwal5776
      @bittooaggarwal5776 3 года назад

      @@channamalleshhiremath6320 thank you so much for clearing the doubt brother.

    • @ravikiran3871
      @ravikiran3871 3 года назад +3

      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.

    • @KartikGhanekar-DSEE
      @KartikGhanekar-DSEE 2 года назад

      @@channamalleshhiremath6320 even if u remove that 2nd sleep u still get random output

  • @shashgo
    @shashgo 7 лет назад +2

    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

  • @mohdezazulhaq1654
    @mohdezazulhaq1654 3 года назад

    As I observed it depends on jvm which thread is selected, so setting priority doesn't make any difference

  • @divineuttrakhand376
    @divineuttrakhand376 5 лет назад

    Just Awesome.. I was not knowing multithreading was so easy before.

  • @Sanjeev1101
    @Sanjeev1101 7 лет назад +2

    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.

  • @bhaskar1843
    @bhaskar1843 6 месяцев назад

    what is the benefit of assigning priority to a thread in the FirstPlace??

  • @krishanprasad3888
    @krishanprasad3888 7 лет назад

    Hi Naveen,
    What is the benefit of defining the thread priority, when they are still printing in same order?

    • @channamalleshhiremath6320
      @channamalleshhiremath6320 4 года назад +2

      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.

  • @cutepuffpaws4420
    @cutepuffpaws4420 2 года назад

    what difference it makes ...?

  • @anmol213565
    @anmol213565 5 лет назад

    what is the use of priority if nothing is changing

  • @omarbakij6313
    @omarbakij6313 4 года назад

    Sir,where i can get the Thread.class so i can see it ?

  • @bhavyasharma3500
    @bhavyasharma3500 5 лет назад +1

    Sir what is the use of setting priority in thread

    • @Doomblud
      @Doomblud 4 года назад +2

      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.

  • @captain-black-1
    @captain-black-1 2 года назад

    helo sir what is the use of setting priority in thread

  • @sgamer8323
    @sgamer8323 4 года назад

    What does high or low priority does?

  • @abhishekpandey8126
    @abhishekpandey8126 6 лет назад

    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.

  • @ronni1154
    @ronni1154 8 лет назад

    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.

  • @ayushyadav4180
    @ayushyadav4180 2 года назад

    is that war going on in background lot of firing

  • @sravanisridhara3029
    @sravanisridhara3029 5 лет назад

    What is the output for change of priority?

  • @nivethithanivetha921
    @nivethithanivetha921 5 лет назад

    Priority does not create any impact in thread processing????

    • @rambir9421
      @rambir9421 4 года назад +1

      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.

  • @anikeatbansal6916
    @anikeatbansal6916 7 лет назад

    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?

    • @Sammy58328
      @Sammy58328 4 года назад

      High Priority threads get more CPU Time.

  • @venpro8705
    @venpro8705 4 года назад

    Hi bro
    Learning java in 2020 is best or not best ?

  • @kawaljeetsingh3521
    @kawaljeetsingh3521 6 лет назад

    But, what is priority?¿?¿?¿?

  • @amrish_kumar142
    @amrish_kumar142 3 года назад

    how to make duplicate fie using multithreading

  • @rajeshdeva5861
    @rajeshdeva5861 8 лет назад

    hlo sir I need some scenario to work out

  • @monukumarmodi6551
    @monukumarmodi6551 5 лет назад

    Purpose of Pirority

  • @BaduguPranay
    @BaduguPranay 6 лет назад

    what was that clapping noise

  • @dontlogin79
    @dontlogin79 4 года назад +2

    00:33 someone get shot?

  • @ahmadalk2540
    @ahmadalk2540 6 лет назад +16

    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
      @divineuttrakhand376 5 лет назад +1

      This is very much understandable that why priority is used even in normal life too.

    • @prince5922
      @prince5922 5 лет назад +1

      @@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.

  • @monirahmedkhan
    @monirahmedkhan 7 лет назад

    i love u