1. 守护线程:
当所有非后台线程都终止后,则虚拟机退出,并且会立即终止这个线程
public class Test {
public static void main(String[] args) {
Thread t = new Thread(new Runnable(){
public void run() {
System.out.println("Daemon thread");
try {
TimeUnit.SECONDS.sleep(10);
System.out.println("守护线程执行完成");
} catch (InterruptedException e) {
}
}
});
t.setDaemon(true);
t.start()