package itat;
public class Example9_20 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Daemon a=new Daemon();
a.A.start();
a.B.setDaemon(true);
a.B.start();
}
}
class Daemon implements Runnable{
Thread A,B;
Daemon(){
A=new Thread(this);
B=new Thread(this);
}
public void run() {
// TODO Auto-generated method stub
if(Thread.currentThread()==A){
for(int i=0;i<8;i++){
System.out.println("i="+i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}else if(Thread.currentThread()==B){
while(true){
System.out.println("线程B是守护线程");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}