p { margin-bottom: 0.21cm; }
后台线程 如果我们对某个线程在启动(调用start 方法)之前 调用setDaemon(true) 方法,这个线程就变成了后台线程
对java 程序来说 只要还有一个前台线程在运行 这个进程就不会结束,如果一个进程中只有后台线程运行,这个线程就会结束
public class TheadDemo1 {
public static void main(String[] args) {
TestThead testThead = new TestThead();
testThead.setDaemon( true );
testThead.start();
System. err .println( "sdf" );
// while (true){
// System.out.println("main"+Thread.currentThread().getName());
// }
}
}
class TestThead extends Thread {
@Override
public void run() {
// TODO Auto-generated method stub
while ( true ) {
System. out .println( "run()" +Thread. currentThread ().getName());
super .run();
}
}