By jj83777
via tutorials.jenkov.com
Published: May 19 2008 / 20:01
This text is no. 11 in a series on Java Concurrency. This text decribes what starvation of threads is, how it can happen in Java, and what you can do to decrease the probability of starvation happening. In other words, what you can do to implement fairness.
Comments
kbilsted replied ago:
Hi Jenkov. Nice article, but it needs a tiny correction ;-) You state "You can set the thread priority of each thread individually. The higher the priority the more CPU time the thread is granted. You can set the priority of threads between 1 and 10." ... this is not correctly correct. According to the specification (at least as how I remember it), it is solely up to the VM implementation whether it wants to enforce the priorities or not. And as a side note, given the way most threads priorities are implemented, there is no guarantee that a thread with priority 10 is executed before one with priority 1.
Jakob Jenkov replied ago:
That is correct. Further, it may also depend on the underlying OS. For instance, I remember reading somewhere that Windows uses thread priorities from 1 to 7. How 1 to 10 is mapped onto 1 to 7 is undefined too. Anyways, I mention the thread priority stuff mostly because it is a possibility, something to keep in mind if you start changing thread priorities. The risk of starvation caused by synchronized blocks and the wait() / notify() mechanism is more "real".
Voters For This Link (9)
Voters Against This Link (0)