• 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: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This is a question from Jexam:
which will definitely stop a thread from executing?
1) stop //true
2)sleep //true
3)suspend //true
4)yield() // given as correct.
But,I have choosen as false.since yield() brings the Thread
to ready state.And it may or may not stop executing
depending on the i/p in Thread Scheduler.
Thanks!

 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is what the Java API Documenation says about the yield() method


Causes the currently executing thread object to temporarily pause and allow other threads to execute.


This means calling yield() will stop the thread atleast momentarily. This behaviour is guaranteed.
As you have observed, what happens next depends on lot of things such as how many threads are waiting in the pool, what is the scheduling policy etc, which is out of the scope of the question.
Hence yield() is also a right answer.
Hope this helps,
Ajith
[This message has been edited by Ajith Kallambella (edited August 15, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!Ajith
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic