package com.bingfeng.huo;
public class TestSleep {
public static void main(String[] args) {
Thread t1 = new Thread() {
@Override
public void run() {
this.setName("守护线程。");
for (int i = 0; i < 2; i++) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(getName() + "..." + i);
}
}
};
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 50; i++) {
System.out.println(Thread.currentThread().getName() + "...." + i);
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
t1.setDaemon(true);
t1.start();
t2.start();
}
}
这个程序为什么守护线程已经结束了,另一个线程还在跑? |
|