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 Thread stop executing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread stop executing" Watch "Thread stop executing" New topic
Author

Thread stop executing

tian Lau
Greenhorn

Joined: Jul 10, 2000
Posts: 20
I got two qs :
What might cause the current thread to stop executing.

A. An InterruptedException is thrown.
B. The thread executes a wait() call.
C. The thread constructs a new Thread.
D. A thread of higher priority becomes ready.
E. The thread executes a waitforID() call on a MediaTracker.
What might cause the current thread to stop executing?

A. An InterruptedException is thrown
B. The thread executes a sleep() call
C. The thread constructs a new Thread
D. A thread of higher priority becomes ready (runnable)
E. The thread executes a read() call on an InputStream
I need your idea to correct myself!!
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Tian,
What do you think the answers are? Think aloud and post your opinions along with the question, it helps others too!
Ajith


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
tian Lau
Greenhorn

Joined: Jul 10, 2000
Posts: 20
sorry I forgot to post mine.
My idea is a b d e for both, what do you think?
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
A - Is debatable.
InterruptedException doesn�t always stop a running thread. The thread could catch the exception and continue running.
B - Yes.
sleep(), wait() or join() stops the running thread.
D. A thread of higher priority becomes ready
C - No!
D - Is debatable.
Though this is usually true, it certainly depends on the implementation of the thread scheduler. For example, a time-slicing scheduler may not honor thread priorities.
E - Yes.
Thread is blocked by an operation and is waiting for something to happen( I/O block for eg).
Here again, you will have to distinguish between "Waiting","Blocked" and "Stopped" states. I hope the questions in the real exam are far more clearer than this.
Ajith
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
A - I think no. For an InterruptedException to be thrown, the thread must have already been waiting or sleeping, right? Then an interrupt() is invoked on the thread, and that acually restarts the execution of the thread. Of course, the execution takes the form of an exception being thrown - but that doesn't stop execution itself. Failing to catch the exception would - but that's a different situation, IMO.
D - Yes, since the question is whether this may stop execution. It certainly can, but as Ajith said, it's not guaranteed.
For the rest I agree with Ajith.

"I'm not back." - Bill Harding, Twister
 
jQuery in Action, 2nd edition
 
subject: Thread stop executing
 
Similar Threads
Thread
Thread
Thread
Please give me reply.
thread