File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread stop executing

 
tian Lau
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tian,
What do you think the answers are? Think aloud and post your opinions along with the question, it helps others too!
Ajith
 
tian Lau
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry I forgot to post mine.
My idea is a b d e for both, what do you think?
 
Ajith Kallambella
Sheriff
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic