守护(daemon)线程
线程分为用户线程和守护线程。
虚拟机必须确保用户线程执行完毕。
虚拟机不用等待守护线程执行完毕
public class TestDaemon {
public static void main(String[] args) {
God god=new God();
You you=new You();
Thread thread=new Thread(god);
thread.setDaemon(true);//默认是false表示用户线程,正确的线程都是用户线程
thread.start();//上帝保佑启动
new Thread(you).start();
}
}
//上帝
class God implements Runnable{

浙公网安备 33010602011771号