public class QqDown implements Runnable{
private int i=0;
@Override
public void run() {
while (true) {
synchronized (this.getClass()) {
try {
Thread.sleep(300);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(i<=100){
System.out.println("已下载了"+i+"%");
}
if(i==100){
System.out.println("有毒,已经下载完成");
break;
}
i++;
}
}
}
public static void main(String[] args) {
Thread t=new Thread(new QqDown(),"下载");
t.setDaemon(true);//后台线程
t.start();//开始现场
try {
t.join();//加入main线程
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} |
|