Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread priority

 
huiying li
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://java.sun.com/docs/books/tutorial/essential/threads/priority.html
Java tutorial states that "Threads can only yield the CPU to other threads of the same priority--attempts to yield to a lower priority thread are ignored."
However this does not seem to be the case. I created two threads, one with higher priority then the other, both call yield in run() method, the results are intermingled, so it seems the yield to lower priority thread did occur. Any explanations are welcome.


[This message has been edited by huiying li (edited March 09, 2001).]
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Huiying,
There are never any guarantees with threads
The JDK for <code>yield()</code> says:

Causes the currently executing thread object to temporarily pause
and allow other threads to execute.

It does not say wether the other thread must have the same, higher or lower priority ... just that it will cause the current thread to pause.
In the end, which thread runs depends on the the way the scheduler is implemented on the local system. As Win98 uses time-slicing, it's possible a lower priority thread could run. On systems that don't use time-slicing, a lower priority thread may not run given a yeild().
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
huiying li
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jane
Many people have said that the questions on Thread are tricky on exam, so I had hoped that the Sun tutorials would help me to prepare for it. I have read Mughal's book. Do you have suggestions on what else to read up for the test?
 
Jane Griscti
Ranch Hand
Posts: 3141
 
Shrini Kulkarni
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not to forget maha's site. www.javaranch.com/maha - refer to discussions on "Threads" topic
Shrinivas
------------------
Sun Certified programmer for Java2 platform.
Shri_mk@hotmail.com
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic