Starvation will definitely not occur when using monitors in Java if notifyAll() is used. F
If a thread is not granted CPU time because other threads grab it all, it is called "starvation". Check here for
more.
- When using
notifyAll()
, JVM awakens all threads and then all
threads race for the lock on this object. Now, CPU scheduler selects
a thread which acquires lock on this object. This means using
notifyAll()
can not avoid starvation since some threads may always lose the contention.
- Also, Threads are blocked indefinately waiting to enter a
synchronized block, because other threads are constantly allowed
access before it. Starvation will also occur.
Only objects that are declared to extend thread or implement runnable
have a monitor lock in Java. F
Every class roots from java.lang.Object
has monitor lock. Check here for more.