Java Thread置空的影响

/**
 * @Author: ZhangHao
 * @Description: ThreadTest
 * @Date: 2020/3/30 14:14
 * @Version: 1.0
 */
public class ThreadTest {
    static Thread thread;
    public static void main(String[] args) {
        thread = new Thread(() -> {
            for(int i = 0;i < 10000;i++){
                System.out.println(1);
            }

            // 不影响run方法的继续执行
            thread = null;

            for(int i = 0;i < 10000;i++){
                System.out.println(2);
            }

            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        });
        thread.start();
    }
}
发布了388 篇原创文章 · 获赞 105 · 访问量 31万+

猜你喜欢

转载自blog.csdn.net/haoranhaoshi/article/details/105201994
今日推荐