About Question enthuware.ocpjp.v7.2.1454 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
jagoneye
Posts: 97
Joined: Wed Dec 28, 2016 9:00 am
Contact:

About Question enthuware.ocpjp.v7.2.1454 :

Post by jagoneye »

There are two possibilities:
1. The current thread is the same object as the subclass of Thread referred to in the question. In this case, calling start() amounts to starting the same thread again. Since the thread is already started, it will throw an exception. However, the thread will not stop running.
2. 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. The current thread will keep running. If the other thread is already started, this call will get an exception. However, that will still not stop the current thread.
How will the current thread keep running if an exception is ecountered???

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

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

Post by admin »

An exception doesn't stop or kill a thread. Only if the exception is not handled, then the thread is killed. So if you put the call to start in try/catch, the thread will still be running.

jagoneye
Posts: 97
Joined: Wed Dec 28, 2016 9:00 am
Contact:

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

Post by jagoneye »

admin wrote:An exception doesn't stop or kill a thread. Only if the exception is not handled, then the thread is killed. So if you put the call to start in try/catch, the thread will still be running.
Oh okay forgot about that! But still suppose if i create a random no of threads from
my main thread and if one of those threads encounter an Exception which is not handled. So in that case if that thread will be killed then will it affect my main threads and the other threads that I created or will they executing normally???

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

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

Post by admin »

If the code that a thread is executing throws an exception that is not handled then that thread dies. Nothing happens to other threads.

jagoneye
Posts: 97
Joined: Wed Dec 28, 2016 9:00 am
Contact:

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

Post by jagoneye »

Thank you very much. That fully cleared my doubts! :)

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests