If I have a thread with a priority of 10 and another with a priority of only 1, is it possible for the thread with the highest priority to dominate to the point that the thread with the lower priority isn't even called -- I understand that instead of yield(), I should use sleep().
Short answer: It's possible. It's called Thread Starvation.
You may want to google for
1. Thread Starvation 2. Thread Busy Wait
I believe you are exploring threads (considering you posted 3 questions). Might be a good idea to invest in a book. I dont know which one, but someone should be able to point you to a good book.
I always find Sun Trails a nice place to start reading about any java features/libraries. You get a broad idea of what is offered and what you should look (google) for. [ November 24, 2006: Message edited by: praveen balaji ]
If it uses FCFS(First Come First Serve) algorithm, you cant avoid starvation(setting all thread of priority 5 or same ).
If system uses RR(Round Robin) algorithm to handle multiple threads no thread starvation will occur(Limitation: this algorithm affects efficency as scheduler will spent most of the time to switch from one thread to another thread in case of very large number of threads).
Correct me for my wrong concepts if there is any in above explanation...........
Originally posted by Kaydell Leavitt: If I have a thread with a priority of 10 and another with a priority of only 1, is it possible for the thread with the highest priority to dominate to the point that the thread with the lower priority isn't even called.
Definitely can, only testing will give meaningful answers. For:
Originally posted by praveen balaji but someone should be able to point you to a good book.
That book is defintely Java Threads, 3rd Edition by Scott Oaks & Henry Wong. I have lots of books, this is an exceptionally good book. Thread starvation, which is the question you are asking, depends on the operating system, the workload and a compiler. Generally, a Thread aware os will silently boost the priority of a lower priority thread if it needs that thread to complete a task; but in the more general case setting a priority of ten will make that thread seem to be the entire machine as long as there is something for it to do.
Can I prevent thread starvation by leaving all threads at a normal priority of 5?
Well yes, but what is the problem you are trying to make an approach to ?
As for sleep() v yield() - I asked about that and use the sleep(0) syntax but I was told that yield() is implemented in the Java Engine, therefore it would be a personal preference which one to use. [ December 17, 2006: Message edited by: Nicholas Jordan ]
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."