• 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

Question on threads

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Under what circumstances might you use the yield method of the Thread class
1) To call from the currently running thread to allow another thread of the same or higher priority to run
2) To call on a waiting thread to allow it to run
3) To allow a thread of higher priority to run
4) To call from the currently running thread with a parameter designating which thread should be allowed to run
My Answer is 2. is it correct? If not how? pls explain....
Which is the correct Answer.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ans 2 is surely wrong.because we should use notify or notifyAll method to tell the the thread in the waiting queue.So a thread(using notify) or all threads(using notifyALL) will be in the ready queue
 
frank fan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ans 2 is surely wrong.because we should use notify or notifyAll method to tell the the thread in the waiting queue.So a thread(using notify) or all threads(using notifyALL) will be in the ready queue
Frank
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer is one, sort of. However, you do not have to call yield to allow a higher priority thread to run; the VM can run it whenever it pleases. Yield does allow a same priority thread to run, but does not guarantee a different thread will run, or that any attention will be paid to the yield call at all.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here are my views
1)To call from the currently running thread to allow another thread of the same or higher priority to run
-->This is not correct completely as any runnable thread will get it's turn to run.
2) To call on a waiting thread to allow it to run
-->what does the waiting thread here imply, if it means any thread that's ready to be run then it's the correct answer,
else if it's the thread waiting implicitly by making a call to wait method then it can resume only when the other Thread which holds lock will call notify or notifyAll method
3) To allow a thread of higher priority to run
--> This is wrong
4) To call from the currently running thread with a parameter designating which thread should be allowed to run
This is obviously wrong.
Here if the author implies that the waiting thread means any thread that's in the state of ready to run then it's the correct answer
else rest are wrong.
 
Every plan is a little cooler if you have a blimp. And a 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