package edu.wzw.Teat;import org.omg.PortableServer.THREAD_POLICY_ID;publicclassTestDaemon{publicstaticvoidmain(String[] args){
God god =newGod();
You you =newYou();
Thread thread =newThread(god);
thread.setDaemon(true);//默认是false表示用户线程,正常的线程都是用户线程
thread.start();//上帝的守护线程启动newThread(you).start();//你的用户线程启动}}classGodimplementsRunnable{@Overridepublicvoidrun(){while(true){
System.out.println("上帝会守护你开心的每一天");}}}classYouimplementsRunnable{@Overridepublicvoidrun(){for(int i =0; i <365; i++){
System.out.println("每一天都在开心的玩耍");}
System.out.println("今天是不开心的一天");}}
守护线程(线程状态)线程分为用户线程和守护线程虚拟机必须确保用户线程执行完毕虚拟机不用等待守护线程执行完毕如,后台记录操作日志,监控内存,垃圾回收等待。。package edu.wzw.Teat;import org.omg.PortableServer.THREAD_POLICY_ID;public class TestDaemon { public static void main(String[] args) { God god = new God();