File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is Thread Starvation History?

 
Kaydell Leavitt
Ranch Hand
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With modern CPUs, modern operating systems, and modern JVMs, is "thread starvation" a problem only in history? It seems like modern CPUs are preemptive as are operating systems. It seems like good JVMs would use preemption too and so thread starvation might not be a problem anymore. Is that true?

Kaydell
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not an expert on the matter, but (e.g.) in Java there's still the concept of "thread priority". Its use is discouraged, but I think lower-priority threads might be starved of CPU cycles on a busy system. But then, probably few systems will be running on 100% for extended periods of time, and low-priority threads can presumably wait a while until they get run; so they may not actually get starved.
 
Henry Wong
author
Marshal
Pie
Posts: 20828
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For "CPU starvation", all OSes do a great job to make sure that threads of the same priority do get a fair time slice of the processor. This was probably true even before Java -- Java just didn't use it in the early years. In that regard, it is highly unlikely threads of the same priority will starve.

Windows goes even further, to allow threads of different priorities to get a "fair" time slice. (lower priorities run for smaller slices and less often)


As for "lock starvation" (threads being starved because they can't access a synchronization lock), all modern OSes support priority inheritance, to prevent a lower priority thread from starving a higher priority thread.


To answer your question, I am sure someone can come up with a scenario when a thread will starve. There is only so much processing power in a system -- and it should be possible to place such a high demand to exceed it. This is one reason why thread pools are still recommended -- to limit the number of threads in an application.

Henry
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf and Henry's answers are good, but I'm not sure they precisely address your question. I think you asked because the early Java literature makes a big deal out of "starvation" because early JVMs used the non-preemptive "Green threads" library. As you suspect, that's not the case anymore, so the general level of urgency of that early literature is no longer warranted.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic