File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes Is Thread Starvation History? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Is Thread Starvation History?" Watch "Is Thread Starvation History?" New topic

Is Thread Starvation History?

Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

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?

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
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

Joined: Sep 28, 2004
Posts: 20534

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.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Is Thread Starvation History?
It's not a secret anymore!