Link Details

Link 81671 thumbnail
User 131196 avatar

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.
  • 9
  • 0
  • 1305
  • 434

Comments

Add your comment
User 246188 avatar

kbilsted replied ago:

0 votes Vote down Vote up Reply

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.

User 131196 avatar

Jakob Jenkov replied ago:

0 votes Vote down Vote up Reply

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

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (9)



Voters Against This Link (0)