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");
}
}
javaSE之多线程之守护线程上帝和你
猜你喜欢
转载自blog.csdn.net/qq_42794826/article/details/108957124
今日推荐
周排行