线程的生命周期的问题

        private boolean flag = true;
        new Thread(new Runnable(){   
            public void run(){   
                while(flag){   
                    try{   
                        Thread.sleep(1000);   
                        System.out.println("输出");
                    }catch(InterruptedException e){   
                    }   
                }   
            }   
        }).start();    

线程里面只有一个while循环,当while循环停止以后,这个线程是否还在运行?

要是不想while里面的代码继续执行,最好把flag设置为false,不要手动去停止线程,容易出错

当while循环停止以后,这个线程停止了。