Thread有守护线程和非守护线程之分。 
守护线程在主线程运行结束后,也会结束运行,而非守护线程不会结束。 
线程默认都是非守护线程。可以使用thread.setDeamon方法来设置。 
system.exit(0); 代表退出进程,无论什么线程都退出。 
下述代码,即使不加System.exit(0),在主线程结束后,其守护线程也会随之中止。 
public class t { 
public static void main(String[] args) { 
System.out.println("kaishi"); 
asd th = new asd(); 
th.setDaemon(true);
th.start(); 
System.out.println(System.currentTimeMillis()); 
System.out.println("tuichu"); 
System.out.println(Thread.currentThread().getName()+System.currentTimeMillis()); 
//System.exit(0); 
} 
} 
class asd extends Thread { 
public void run() { 
while (true) { 
System.out.println(Thread.currentThread().getName()+System.currentTimeMillis()); 
} 
} 
}