• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

thread priority

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Hey cool! They got a blimp! But I have a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic