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  About 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 " About Thread question?" Watch " About Thread question?" New topic
Author

About Thread question?

Ma JianHui
Greenhorn

Joined: Mar 01, 2008
Posts: 6
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:A,E

I think the answer is wrong,because the method yield() cannot directly cause a thread to stop executing!
which methods can directly cause a thread to stop executing?
Thanks!!!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14150
    
  18

Welcome to JavaRanch.

When you copy a question from a mock exam or book, we ask you to quote your sources. So, please tell us where you copied the question from.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
David Grant
Greenhorn

Joined: Apr 01, 2008
Posts: 13
From the API:

public static void yield()

Causes the currently executing thread object to temporarily pause and allow other threads to execute.


So, as far as I can see, the answer to the question should be E only.
Sharma Tarun
Greenhorn

Joined: Jan 12, 2008
Posts: 12
It does not ask whether it stops temperorily or permanently. So, I thonk the answer is correct.
Sandeep Bhandari
Ranch Hand

Joined: Apr 16, 2004
Posts: 201
First to quote the source: Sun's SCJP1.5 e-Practice Exam

Even then notify doesn't cause a thread to stop.
I think the sense of the question is to ask about methods which stop an executing thread and out of those identify which directly cause the thread to stop.

As explained above notify and notifyAll don't cause a thread to stop (so no question of stopping it directly)

Now calling the wait method causes the thread to stop and wait (waiting from running)

The call to start on some thread or the call to yield doesn't mean a thread will be stopped. Its a matter chance which depends upon the current situation and thread scheduler.

As an example:
A thread is already running and start method is called on some other thread. We can't say that first thread will be stopped. It depends upon thread priority, thread scheduler etc.

Now calling the yield() method on a thread makes the thread to go to waiting state so that some other waiting thread may be given resources. But what if there is no other waiting thread?? The thread will continue to run.


Hope that makes things clear!!


SCJP 96% | SCWCD 90%| SCJP mock exams | My SCJP blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About Thread question?