File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes thread priority Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "thread priority" Watch "thread priority" New topic
Author

thread priority

huiying li
Ranch Hand

Joined: Feb 12, 2001
Posts: 68
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).]


SCJP
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
huiying li
Ranch Hand

Joined: Feb 12, 2001
Posts: 68
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

Joined: Aug 30, 2000
Posts: 3141
Hi Huiying,
Here's are some links that may be helpful:
IBM Redbook: Java Thin-Client Programming - Introduction to Threads
SunTech Tip: Why Use Threads?
Exploring Java, Chapter 6, Threads
Beware the daemons
Sun Tech Tip: Handling Interrupted Exceptions
Sun Tech Tip: Using Synchronized Statements
Acquire multiple locks in a fixed, global order to avoid deadlock
Hope they help.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Shrini Kulkarni
Ranch Hand

Joined: Jan 12, 2001
Posts: 63
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


Sun Certified programmer for Java2 platform.<BR>Shri_mk@hotmail.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: thread priority