File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes My Confusion About Thead Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "My Confusion About Thead" Watch "My Confusion About Thead" New topic
Author

My Confusion About Thead

Neo Xiang
Greenhorn

Joined: Jul 21, 2002
Posts: 8
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 :<
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
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.


SCJP2. Please Indent your code using UBB Code
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Excellent answer, Jose, can we stick that one in the SCJP2 FAQ?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Maybe it needs a bit of more work for that. But you can have a collection of good answer's URLs as I have.
 
 
subject: My Confusion About Thead