• 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

yield()

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following will definitely stop a thread from executing:
wait()
notify()
yield()
suspend()
sleep()
my ans is wait(),suspend(),sleep()
but Jxam says yield() is also correct.am i missing something
Thanks
Hima
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think yield() is, technically, a correct answer since calling yield() causes the currently running thread to return to the ready state and allows the VM to decide which thread to continue with. This is not to say that that the VM will not possibly pick the same thread that just yielded and continue (to the eye of the suer) as if nothing had happened. I suppose the point that they are after is that the running thread must stop executing for some period of time, even if that thread is re-chosen by the VM. This seems like a loaded, if not poorly worded question.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah!
yield will cause thread itself give up the CPU time and turned to ready status until JVM re-call it run.it is "run"->"ready",but also stop execute
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, yield() is just a suggestion made to the thread scheduler that the current thread is not doing anything very interesting at the moment, and if it wants, it can go ahead and run a different thread.
Since it's just a suggestion, there's no guarantee about the behavior on a particular implementation of a JVM. In fact, on a multiple processor system, a good thread scheduling algorithm will just ignore your yield() call, since it can do a far better job of thread balancing that you can as a programmer.
So, it's not correct to say that "calling yield() will definately stop a thread from executing."
 
I'm so happy! And I wish to make this tiny ad happy too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic