62,614
社区成员
发帖
与我相关
我的任务
分享
/**
* @author :jiaolian
* @date :Created in 2021-01-28 14:50
* @description:回收线程测试
* @modified By:
* 公众号:叫练
*/
public class GCThreadTest {
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(()->{
while (true){}
});
thread.start();
Thread.sleep(1000);
thread = null;
}
}
用实例说话,1秒后thread 线程还在运行,说明线程不会被回收。同时印证了楼上大佬说的"对于线程对象的垃圾回收,垃圾回收器有特殊的处理",多动手理解的可能更深刻,希望回答对你有所帮助!