After completion, the java thread will be deleted

I use the following method to generate a thread every few seconds. Each thread takes about a second to complete Are completed threads deleted?

new Thread (new myRunnableClass()).start();

Solution

After the thread completes, the native OS level thread is released (roughly when run() completes), but the thread object lives like any other object until it becomes inaccessible and the garbage collector feels like running

Edit: it may be interesting that a thread (in sun's Oracle implementation, anywho) has a private method called by the VM when the thread exits, which will make a large number of fields null, including referencing the runnable constructor set by the thread So even if you keep the reference to the thread, what it doesn't need will be released after execution, anyway

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>