About Question enthuware.ocpjp.v7.2.1454 :
Moderators: Site Manager, fjwalraven
-
- Posts: 14
- Joined: Thu Apr 18, 2013 2:05 pm
- Contact:
About Question enthuware.ocpjp.v7.2.1454 :
how interrupt() will not causes to stop executing thread ? it will throw interruptedException, which will terminate thread.
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1454 :
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.
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 14
- Joined: Thu Apr 18, 2013 2:05 pm
- Contact:
-
- Posts: 132
- Joined: Thu May 16, 2013 9:23 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1454 :
Hi,
If you restart a thread you get an exception and then the program terminates, hence the thread gets stopped.
The_Nick.
If you restart a thread you get an exception and then the program terminates, hence the thread gets stopped.
The_Nick.
-
- Posts: 19
- Joined: Thu Feb 28, 2013 9:47 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1454 :
The wait() method stop a thread or only pause a thread since another thread call notify / notifyAll ?
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1454 :
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.
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 5
- Joined: Fri Jan 17, 2014 6:08 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1454 :
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.
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1454 :
No, the question is asking, "Which of the following calls will not stop a thread from executing ?" so the given answer is correct.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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 53
- Joined: Thu Nov 22, 2012 12:01 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1454 :
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.
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1454 :
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.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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 28
- Joined: Fri Jan 02, 2015 12:13 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1454 :
The reasoning for option 1 (calling start by the current thread from a subclass of Thread class) seems to be incomplete:
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:
How do we know here that the Thread object referred to by `this' was not started before?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...
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?
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1454 :
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.
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.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 9 guests