About Question enthuware.ocpjp.v7.2.1454 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
arnoldnitesh
Posts: 14
Joined: Thu Apr 18, 2013 2:05 pm
Contact:

About Question enthuware.ocpjp.v7.2.1454 :

Post by arnoldnitesh »

how interrupt() will not causes to stop executing thread ? it will throw interruptedException, which will terminate thread.

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1454 :

Post 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.
If you like our products and services, please help us by posting your review here.

arnoldnitesh
Posts: 14
Joined: Thu Apr 18, 2013 2:05 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1454 :

Post by arnoldnitesh »

Thanks

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1454 :

Post 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.

muttley
Posts: 19
Joined: Thu Feb 28, 2013 9:47 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1454 :

Post by muttley »

The wait() method stop a thread or only pause a thread since another thread call notify / notifyAll ?

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1454 :

Post 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.
If you like our products and services, please help us by posting your review here.

mdraisma
Posts: 5
Joined: Fri Jan 17, 2014 6:08 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1454 :

Post 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.

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1454 :

Post 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.
If you like our products and services, please help us by posting your review here.

icepeanuts
Posts: 53
Joined: Thu Nov 22, 2012 12:01 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1454 :

Post 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.

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1454 :

Post 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.
If you like our products and services, please help us by posting your review here.

disznoperzselo
Posts: 28
Joined: Fri Jan 02, 2015 12:13 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1454 :

Post 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?

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1454 :

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests