public class Daemon implements Runnable {
Thread A,B;
public Daemon() {
A = new Thread(this);
B = new Thread(this);
}
@Override
public void run() {
Thread t = Thread.currentThread();
if(t == A){
for (int i = 0; i < 8; i++) {
System.out.println("i = " + i);
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {}
}
}else if(t == B){
while(true){
System.out.println("线程B是守护线程");
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {}
}
}
}
}
为什么程序的运行结果是无数个 "线程B是守护线程",而另一个线程A并没有执行呢
逆光之羽
慕的地8582982
逆光之羽
相关分类