import java.util.Timer;
import java.util.TimerTask;
public class Test {
static int k = 1;
private static int delay = 1000;
private static int cacheTime = 1000;
private static int cacheTime1 = 8000;
public static void main(String[] args) {
t1();
t2();
}
public static void t1(){
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("打印");
}
}, delay, cacheTime);//延迟delay毫秒后,执行第一次任务,每隔cacheTime毫秒后执行任务
}
public static void t2(){
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("测试");
}
}, delay, cacheTime1);
}
}
任务t1和t2