It seems that the answer "A thread dies when the run( ) method ends." is less accurate that the answer "A thread dies when the start() method ends". It is because of two reasons:
1. Method run() could be executed without starting a new thread, so when it ends the execution the thread keeps the NEW State.
2. Decompiling of the Thread class shows that the start() method wraps around a native private method start0() which calls run() method and set a thread state to TERMINATED inside.
In both cases we can not definitely say whether a thread dies after finishing run() execution or not(in the 1st case the answer is always NO) . However it is always true that every thread is died when it finishes the start() execution .
About Question enthuware.ocpjp.v7.2.1441 :
Moderator: admin
-
- Posts: 1
- Joined: Sat Dec 12, 2015 11:23 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1441 :
1. start method returns immediately after kicking of the run method. So saying a thread dies after start ends would be incorrect.
2. If you call the run method directly, you are not really creating a thread. There is no thread in that case. So the question whether a thread dies or not does not arise. But the option is specifically talking about a thread and its run method. Also, the option does not talking about "calling" the run method. It is only talking about its execution. A thread is alive only until its run method is executing. It does die as soon as the run method ends.
HTH,
Paul.
2. If you call the run method directly, you are not really creating a thread. There is no thread in that case. So the question whether a thread dies or not does not arise. But the option is specifically talking about a thread and its run method. Also, the option does not talking about "calling" the run method. It is only talking about its execution. A thread is alive only until its run method is executing. It does die as soon as the run method ends.
HTH,
Paul.
Who is online
Users browsing this forum: No registered users and 6 guests