aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "thread question" Watch "thread question" New topic
Author

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
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

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
Hi,
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.

Regards
Abhijit.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

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.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: thread question