Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If return statement is executed in run function of a thread does the thread stop in java

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;
}
like image 426
sayem siam Avatar asked Oct 22 '25 07:10

sayem siam


1 Answers

Yes, a Java thread stops when its run method terminates.

Now, this information is, let's say, "common knowledge", because the purpose of the Thread class 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 start0 is executed.

like image 172
Tudor Avatar answered Oct 23 '25 21:10

Tudor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!