aspose file tools*
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
Author

Is Thread Starvation History?

Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 688

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
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18120
    
  39

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


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

Joined: Jul 08, 2003
Posts: 24166
    
  30

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: http://aspose.com/file-tools
 
subject: Is Thread Starvation History?
 
Similar Threads
jtips quiz 3
Thread Starvation
64 bit and 32 bit ?
Dual processor utilization
Inturrupting a Thread, Killing a Thread