Page 1 of 1

About Question enthuware.ocpjp.v7.2.1454 :

Posted: Wed Jan 11, 2017 9:37 am
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???

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

Posted: Wed Jan 11, 2017 12:00 pm
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.

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

Posted: Wed Jan 11, 2017 12:04 pm
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???

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

Posted: Wed Jan 11, 2017 1:16 pm
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.

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

Posted: Wed Jan 11, 2017 1:18 pm
by jagoneye
Thank you very much. That fully cleared my doubts! :)