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();
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章