This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on threads

 
majohnad majohnad
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
frank fan
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Bryan Helm
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Praveen Kumar Mathaley
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic