Page 1 of 1
About Question enthuware.ocpjp.v7.2.1454 :
Posted: Thu May 02, 2013 2:58 pm
by arnoldnitesh
how interrupt() will not causes to stop executing thread ? it will throw interruptedException, which will terminate thread.
Re: About Question enthuware.ocpjp.v7.2.1454 :
Posted: Thu May 02, 2013 3:07 pm
by admin
No, that is not correct. Interrupt only sets the interrupted status of a thread.
Further, if the thread is waiting or sleeping, an InterruptedException is thrown but that doesn't mean the thread is stopped.
Please go through this:
http://docs.oracle.com/javase/7/docs/ap ... #interrupt().
-Paul.
Re: About Question enthuware.ocpjp.v7.2.1454 :
Posted: Thu May 02, 2013 3:14 pm
by arnoldnitesh
Thanks
Re: About Question enthuware.ocpjp.v7.2.1454 :
Posted: Wed Sep 18, 2013 3:31 pm
by The_Nick
Hi,
If you restart a thread you get an exception and then the program terminates, hence the thread gets stopped.
The_Nick.
Re: About Question enthuware.ocpjp.v7.2.1454 :
Posted: Mon Nov 25, 2013 6:28 am
by muttley
The wait() method stop a thread or only pause a thread since another thread call notify / notifyAll ?
Re: About Question enthuware.ocpjp.v7.2.1454 :
Posted: Mon Nov 25, 2013 8:29 am
by admin
You could say that it is paused because it may (or may not, if nobody calls notify) start again. But it is still stopped i.e. not running after calling wait.
BTW, stop is not an official state. It is just a term to indicate that a thread is not running (it could be dead or just waiting). Official states are described here:
http://docs.oracle.com/javase/7/docs/ap ... State.html
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1454 :
Posted: Thu Feb 20, 2014 7:51 am
by mdraisma
Can it be that the colors of the right answers are misplaced? I think the right answers should be wait, notify and interrupt, instead of start, notify and interrupt.
Re: About Question enthuware.ocpjp.v7.2.1454 :
Posted: Thu Feb 20, 2014 9:33 am
by admin
mdraisma wrote:Can it be that the colors of the right answers are misplaced? I think the right answers should be wait, notify and interrupt, instead of start, notify and interrupt.
No, the question is asking, "Which of the following calls will
not stop a thread from executing ?" so the given answer is correct.
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1454 :
Posted: Fri Mar 07, 2014 11:13 pm
by icepeanuts
I think the answer "start()" is incorrect because the call to start() on an already started thread causes an IllegalThreadStateException, thus stopping the thread from running.
Re: About Question enthuware.ocpjp.v7.2.1454 :
Posted: Sat Mar 08, 2014 4:34 am
by admin
icepeanuts wrote:I think the answer "start()" is incorrect because the call to start() on an already started thread causes an IllegalThreadStateException, thus stopping the thread from running.
That is not true. Exception is thrown to the thread that calls the start(). The thread on which start() is called is not affected. Further, the caller thread is not stopped either. It can catch the exception and move on.
Re: About Question enthuware.ocpjp.v7.2.1454 :
Posted: Sun Jan 18, 2015 2:55 am
by disznoperzselo
The reasoning for option 1 (calling start by the current thread from a subclass of Thread class) seems to be incomplete:
There are two possibilities:
1. The current thread is a different object than the given subclass of Thread referred to in the question. In this case, a new thread will be started...
How do we know here that the Thread object referred to by `this' was not started before?
Another quote: How can a thread call a method if it is not the current thread? According to this can we simplify the question to:
Which of the following calls made from a subclass of Thread class will NOT stop the current thread from executing?
Re: About Question enthuware.ocpjp.v7.2.1454 :
Posted: Sun Jan 18, 2015 10:16 pm
by admin
You are right. The other thread may or may not be started already. In both the cases though, the current thread will not stop.
You can call a method on any other thread using its reference. For example, t.start(); where t is a reference to other thread.
thank you for your feedback!
HTH,
Paul.