Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Another Thread Q from Dans study guide  RSS feed

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After invoking the wait method on an Object, Obj1, a Thread, T1, will remain in the wait set of Obj1 until which of the following occurs?
a. Another Thread invokes the notify method on the Object, Obj1, and T1 is selected to move out of the wait set.
b. Another Thread invokes the notifyAll method on the Object.
c. Another Thread invokes the resume method on Thread T1.
d. Another Thread interrupts Thread T1.
e. The priority of Thread T1 is increased.
f. A specified timeout period has elapsed.
g. Another Thread invokes the join method on Thread T1.
h. None of the above.
Answer : a b d f
Can someone explain why b?
(b) Notify All does not garuntee that this waiting thread will not wait any more right...because another thread could me chosen instead of T1. Shouldnt the choice say
"Another Thread invokes the notifyAll method on the Object and T1 is selected to move out of the wait set"?
 
Monisha Talwar
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I got this from the JLS


Some other thread invokes the notify method for that object and thread T happens to be the one arbitrarily chosen as the one to notify.
Some other thread invokes the notifyAll method for that object.
If the call by thread T to the wait method specified a timeout interval, the specified amount of real time has elapsed.


So the answer definately complies with that.
Infact just read another quote from Kathy / Bert which says


In most scenarios, it's preferable to notify all of the threads that are waiting on a particular object. If so you can use notifyAll() on the object to let all the threads rush out of the waiting area and back to runnable.


I guess I carelessly assumed that only 1 thread was picked to go to runnable and then to running state, but indeed, all go into runnable, and then 1 to running state!
Sorry, my bad!!
 
grapes are vegan food pellets. Eat this tiny ad:
Download Free Java APIs to Work with Office Files and PDF
htttp://www.e-iceblue.com/free-apis.html
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!