线程结束时会发生什么?
一旦线程到达末端,会发生什么?它会自杀吗?或者它是否漂浮在内存中占用空间?到底发生了什么?
new Thread(new Runnable() {
public void run() {
//do some stuff
...
//ok... did some stuff, now what?
}
}).start();
What happens to a thread once it hits the ends? Does it kill itself? or does it float around in memory taking up space? what exactly happens?
new Thread(new Runnable() {
public void run() {
//do some stuff
...
//ok... did some stuff, now what?
}
}).start();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它完成并且它的所有 ThreadLocal 对象都符合垃圾回收的条件。
It finishes and all it's ThreadLocal objects become eligible for Garbage collection.
它只是像正常的程序一样结束。垃圾收集器可以回收它占用的内存。如果您希望线程继续运行,您可以将其与 while 循环等一起使用。
It just simply ends like a normal piece of program. and Garbage Collector can recycle the memory it took. If you want the thread continues to run, you would use it with a while loop or so.