File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes thread question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "thread question" Watch "thread question" New topic

thread question

K Vidhyakar
Ranch Hand

Joined: Jul 10, 2005
Posts: 68
hi friends,
i dint understand the phrase "cannot directly cause a thread to stop executing" .
Which two CANNOT directly cause a thread to stop executing? (Choose Two)
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.
Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

From what i can tell wait is the only option here that can stop a thread. So i dont understand why the question says ( Choose two ).

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Abhijit Sontakey
Ranch Hand

Joined: Sep 26, 2005
Posts: 67
The answers would be notify and notifyAll().
wait() and yield directtly stop the current thread from executing.
However after invoking notify() and notifyAll() methods, the current thread doesn't stop executing, only after the current thread has completed, rest of threads can execute. If a thread calls start() method of another thread (threadB), if a VM runs another thread(threadB) current thread stops. Hence notify() and notifyAll() are right answers.
Let me know if this helps.

Henry Wong

Joined: Sep 28, 2004
Posts: 20517

Yes... notify() and notifyAll() does not have a direct affect at stopping the current thread.

As for start(), it can have a direct affect, if the thread to be started is of a higher priority.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: thread question
jQuery in Action, 3rd edition