守护线程

package state;

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 You implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 36500; i++) {
            System.out.println("你开心地活着");
        }
        System.out.println("=====goodbye world !");
    }
}
class God implements Runnable{
    @Override
    public void run() {
        while (true){
            System.out.println("上帝守护着你");
        }
    }
}
posted @ 2023-03-11 10:23  北极有熊ovo  阅读(17)  评论(0)    收藏  举报