File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

My Confusion About Thead

 
Neo Xiang
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • 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 :<
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent answer, Jose, can we stick that one in the SCJP2 FAQ?
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic