• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Yielding Threads

 
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Cowpokes,
yield() confuses me a little. The definition from the venerable RHE guys says that "A call to the yield() method causes the currently executing thread to move to the Ready state if the scheduler is willing to run any other thread in place of the yielding thread." Okay, that makes perfect sense. But what strikes me is, if the scheduler is willing to do that, won't it just go ahead and DO it? If the scheduler is willing to do that and it doesn't, why not? What is the difference between when a scheduler is WILLING to do it and when a scheduler actually decides to go ahead and do it (and please don't just say the difference is yield() )? Thanks.
Matt
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on some other factors. Like how priorities are implemented in the specific plateform you are in. So, to say that "if the scheduler is willing to" is a kind of poetry to express the complexity made by the number of other factors.
This is only my little opinion.
Claude

[This message has been edited by Claude Rouleau (edited October 27, 2000).]
 
Enthuware Software Support
Posts: 4818
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, yield() comes in handy when the OS (depending on its scheduling policies) doesn't give CPU to lower priority threads if a higher priority thread is running. Now, as you cannot assume the OS scheduling policy, it is generally a good idea for a CPU intensive thread to call yield() time to time.
Now moving to your questions, calling yield() tells the scheduler that this thread is willing to give up the CPU for some time (basically, lowering it's priority temporarily). If the scheduling policy is such that it never gives CPU to lower priority threads, then it can give the CPU to such threads now.
Had there been no yield() (or something similar) such a scheduler would never give time to lower priority threads if a higher priority thread is ready to run.
Again, it depends on the JVM and the underlying OS Thread scheduler, how/when they actually swap the higher priority thread.
HTH,
Paul.

------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus
 
Matt DeLacey
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the help. One last question. Am I to assume that on an OS that schedules using time-slicing that this is not a factor so much (other than not wanting to violate the write once, run anywhere creed)? Thanks.

Matt
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic