Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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: 20023

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: thread question
It's not a secret anymore!