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
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.
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
Highly recommended series about Multithreading concepts, excellent explanation
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().
on the context of which question are you asking?
@@codewithease-byvarshaI meant when we have multiple thread, and we call notify(), which method will get call first?
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.
👍👍