黑马程序员技术交流社区
标题:
守护线程
[打印本页]
作者:
feey
时间:
2016-5-24 23:27
标题:
守护线程
public class Daemon {
/**
* 守护线程
*/
public static void main(String[] args) {
Thread t1 = new Thread() {
public void run() {
for (int i = 0; i < 2; i++) {
System.out.println(getName() + ".....aaaa");
}
}
};
Thread t2 = new Thread() {
public void run() {
for (int i = 0; i < 20; i++) {
System.out.println(getName() + ".....bbbb");
}
}
};
t2.setDaemon(true);
t1.start();
t2.start();
}
}
作者:
18972877005
时间:
2016-5-24 23:45
学的真不错啊,学到哪啦
作者:
liuqjss
时间:
2016-5-25 00:02
你说下守护线程和非守护线程的作用吗,什么时候用到守护线程
作者:
feey
时间:
2016-5-25 00:07
liuqjss 发表于 2016-5-25 00:02
你说下守护线程和非守护线程的作用吗,什么时候用到守护线程
当所有非守护线程结束,守护线程自动退出(jvm不会等待其结束);
需要在start()方法
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2