I was confused that a thread is automatically stops after executing the return statement or it still remains alive.
This is code like:
public void run{
//code goes here
return;//does the thread stops here;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, a Java thread stops when its
runmethod terminates.Now, this information is, let’s say, “common knowledge”, because the purpose of the
Threadclass is to wrap a portion of code and terminate when the code finishes executing.There is no explicit way to assert this behavior by studying the source code of java.lang.Thread because at some point a native method called
start0is executed.