今天研究time类的使用,首先先建一个类继承自TimerTask类,重写run方法
public class MyTask extends TimerTask{ @Override public void run() { System.out.println("Hello"); } }
之后在主函数中这样写
Timer timer = new Timer(); timer.schedule(new MyTask(),1000,2000);
这样就可以在10秒后执行任务,每20秒执行一次