上海哪里有做网站的,微网站开发 付费阅读,网站策划网站建设企业,国内外婚纱网站建设现状线程分用户线程和守护线程
虚拟机必须确保用户线程执行完毕
虚拟机不用等待守护线程执行完毕
后台记录操作日志#xff0c;监控内存#xff0c;垃圾回收
package com.wuming.state;
//测试守护线程
//上帝守护你
public class TestDaemon {public static void main(Strin…线程分用户线程和守护线程
虚拟机必须确保用户线程执行完毕
虚拟机不用等待守护线程执行完毕
后台记录操作日志监控内存垃圾回收
package com.wuming.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{/*** When an object implementing interface codeRunnable/code is used* to create a thread, starting the thread causes the objects* coderun/code method to be called in that separately executing* thread.* p* The general contract of the method coderun/code is that it may* take any action whatsoever.** see Thread#run()*/Overridepublic void run() {while(true){System.out.println(上帝保佑着你);}}
}
//你
class You implements Runnable{/*** When an object implementing interface codeRunnable/code is used* to create a thread, starting the thread causes the objects* coderun/code method to be called in that separately executing* thread.* p* The general contract of the method coderun/code is that it may* take any action whatsoever.** see Thread#run()*/Overridepublic void run() {for (int i 0; i 36500; i) {System.out.println(你一生都开心的活着);}System.out.println(goodbyeworld!!);}
}