javaSE之多线程之守护线程上帝和你

    科技2025-01-18  5

    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 God implements Runnable{ @Override public void run() { while (true){ System.out.println("上帝保佑你"); } } } //你 class You implements Runnable{ @Override public void run() { for (int i = 0; i < 36500; i++) { System.out.println("你一生都开心的活着"); } System.out.println("=====goodbye! world"); } }
    Processed: 0.012, SQL: 8