1、 5秒后调用(只调一次)
public static void main(String[] args) {
Timer t = new Timer();
//在5秒之后执行TimerTask的任务
t.schedule(new TimerTask(){
public void run(){
System.out.println("----5秒后出现");
}
},5*1000);//时间(毫秒)
}
2、5秒后执行,执行3次
public static void run() throws InterruptedException{
int index = 0;
final int count = 3;//执行次数
do{
Thread.sleep(5*1000);//时间(毫秒)
index++;
System.out.println("test:"+index);;
}while(index<count);
}
public static void main(String[] args) {
try {
run();
} catch (InterruptedException e) {
e.printStackTrace();
}
}