• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Thread stop executing

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic