package thread;
public class DaemonThread extends Thread{
DaemonThread(String name){
super(name);
}
@Override
public void run() {
for(int i=1;i<=100;i++){
System.out.println("更新包下载中"+i+"%");
if(i==100){
System.out.println("下载完成");
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
DaemonThread d=new DaemonThread("后台下载");
d.setDaemon(true);;//设置d 为守护线程
System.out.println(d.isDaemon());
d.start();
for(int i=1;i<=100;i++){//主线程完毕 守护线程也终止
System.out.println(Thread.currentThread().getName()+i);
}
}
}