• 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

My Confusion About Thead

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
11. Which two methods may not directly cause a thread to stop executing?
A. sleep();
B. stop();
C. yield();
D. wait();
E. notify();
F. notifyAll()
G. synchronized()
Answer:EF
73. which two cannot directly cause a thread to stop executing?
A.calling the yield method
B.calling the wait method on an object
C.calling the notify method on an object
D.calling the notifyAll method on an object
E.calling the start method on another thread object
Answer:AE
74.Which two cannot directly cause a thread to stop executing?
A.exiting from a synchronized block
B.calling the wait method on an object
C.calling the notify method on an object
D.calling a read method on an InputStream object
E.calling the setPriority method on a thread object
Answer:CE
Can anyone explain to me the why r the final answer? or r the answers true or not?
i've got confused after these 3 Qs :<
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A. sleep();
The current thread executing this call will stop (temporarily) execution
B. stop();
The thread object on which this method was invoked will stop execution
C. yield();
As a consequence of this call the scheduler could choose another thread to execute. This is not "directly".
D. wait();
The current thread executing this call will stop untill it happens to be awaken as result of a notify...
E. notify();
The calling thread will continue executing after this call. No one is stopped.
F. notifyAll()
The calling thread will continue executing after this call. No one is stopped.
G. synchronized()
Does it mean entering a synchronized block? The executing thread should "stop" untill the lock is available.
E.calling the start method on another thread object.
This call, by itself, cannot make another thread to stop. If the starting thread would have a bigger priority the scheduler may choose to execute it instead of other. I do not think this qualifies to "directly stop" a thread.
A.exiting from a synchronized block
The thread will continue with the unsynchronized part of the task.
D.calling a read method on an InputStream object
The method could block, "stopping" the thread.
E.calling the setPriority method on a thread object.
Again, the scheduler is responsible for the consequences of this call, not a "direct" way.
Do not worry about the ambiguity of these questions. The exam will be accurate.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent answer, Jose, can we stick that one in the SCJP2 FAQ?
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe it needs a bit of more work for that. But you can have a collection of good answer's URLs as I have.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic