package edu.wtbu;标签:God,System,线程,new,public,守护 From: https://www.cnblogs.com/123456dh/p/17229629.html
//测试守护线程
//上帝守护你
public class Demo07 {
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 <30000 ; i++) {
System.out.println("开心过好每一天");
}
System.out.println("你si了");
}
}