Top 9 Interview Questions on wait(), notify() & notifyAll() | Multithreading | Core JAVA QnA

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

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

  • @aishwaryakempu5729
    @aishwaryakempu5729 2 месяца назад

    For Notify() only one random waiting thread will be awakened and in NotifyAll(), though all waiting threads are awaken, only priority threads will acquire the lock. Looks like fairness is missing in NotifyAll only and NotifyAll can cause low priority threads into starvation

  • @masoodsyed794
    @masoodsyed794 4 месяца назад

    Highly recommended series about Multithreading concepts, excellent explanation

  • @ArjunKumar-zu2kl
    @ArjunKumar-zu2kl 9 месяцев назад

    Threads has priority from 1 to 10 so based on that it should get notified, isn't it? We can set the priority with setPriority().

    • @codewithease-byvarsha
      @codewithease-byvarsha  9 месяцев назад

      on the context of which question are you asking?

    • @ArjunKumar-zu2kl
      @ArjunKumar-zu2kl 9 месяцев назад

      @@codewithease-byvarshaI meant when we have multiple thread, and we call notify(), which method will get call first?

    • @codewithease-byvarsha
      @codewithease-byvarsha  9 месяцев назад +1

      When you have multiple threads waiting on an object's monitor and you call notify() on that object, there's no guaranteed order in which the waiting threads will be notified. It's up to the JVM's thread scheduler to decide which thread gets notified first.
      The notify() method wakes up one of the threads that are waiting on the object's monitor, but it's unspecified which one will be awakened. This is what I covered in the video. And thread priority has nothing to do with this.

  • @anulipidas8300
    @anulipidas8300 Год назад

    👍👍