• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

yield or join

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i came across this question in K&B1.4 Threads chapter....

Which three guarantee that a thread will leave the running state?
A. yield()
B. wait()
C. notify()
D. notifyAll()
E. sleep(1000)
F. aLiveThread.join()
G. Thread.killThread()

answer is B, E, and F.

B and E are fine but for F the explanation was based on the assumption that aLiveThread is alive. But then can't we say that option A is also correct if we assume there are some threads of same priority as the current thread in runnable state.

Plz help ...

Asha
 
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I think the key is the word "guarantee". yield is more of a suggestion to the scheduler, and as you pointed out, there might not even be other threads to yield to. That aLiveThread is a live thread is implied by the variable name. That's more of a K&B thing than an exam thing. In a real program, aLiveThread may be in different states at different times, but in a K&B self-test, you can assume it is what it says it is.
 
reply
    Bookmark Topic Watch Topic
  • New Topic