• 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

What is the guaranteed behaviour of yield()

 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the guaranteed behaviour of yield() method(if any)?
Thanx in advance
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm. I am not really sure if the yield() behaviour can be guaranteed. OS may play a crucial rule .
It main job is to yield() for other thread to use the CPU cycles. But if no thread is available it will come back again to Ready to Run state..

[This message has been edited by Ragu Sivaraman (edited October 12, 2001).]
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi leena,
The current thread gives up control of CPU to the threads of same or higher priority waiting in Ready to Run state.however, if no thread of same or higher priority is found,it will continue to run.
rajashree.
 
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 leena,
Believe the only thing that is guaranteed is that the thread will pause while it notifies the Thread Scheduler it is willing to relinquish the lock.
Whatever happens after that is up to the Thread Scheduler. Scheduler's behave differently based on the operating system.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited October 13, 2001).]
 
leena rane
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx a lot Jane
(Thanx Ragu and Rajashree too)
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jane, Thanks for ur reply, is it true that only yield() and wait() releases the lock and sleep(long millisecond) dont.
--Farooq
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only wait() releases the lock.

yield() and sleep() don't.

See this thread
[This message has been edited by Marilyn deQueiroz (edited October 16, 2001).]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Summary:

(1)yield(): releases control to the same or higher priority thread.
              It gives the same priory thread a chance to run.
(2)sleep(): releases control to lower, the same, or higher priority thread.
              It gives lower priory thread a chance to run.
Vincent Yeh
SCJP2, RHCE

[This message has been edited by Vincent Yeh (edited October 16, 2001).]
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this 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