How will the current thread keep running if an exception is ecountered???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.
About Question enthuware.ocpjp.v7.2.1454 :
Moderator: admin
-
- Posts: 97
- Joined: Wed Dec 28, 2016 9:00 am
- Contact:
About Question enthuware.ocpjp.v7.2.1454 :
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1454 :
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.
-
- Posts: 97
- Joined: Wed Dec 28, 2016 9:00 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1454 :
Oh okay forgot about that! But still suppose if i create a random no of threads fromadmin 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.
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???
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1454 :
If the code that a thread is executing throws an exception that is not handled then that thread dies. Nothing happens to other threads.
-
- Posts: 97
- Joined: Wed Dec 28, 2016 9:00 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1454 :
Thank you very much. That fully cleared my doubts! 

Who is online
Users browsing this forum: Google [Bot] and 4 guests