AJPFX关于Timer类的学习
- Timer类:计时器
public class Demo1 {
public static void main(String[] args) throws InterruptedException {
Timer t = new Timer();
// 在指定时间安排指定任务
// 第一个参数,是安排的任务,第二个参数是执行的时间,第三个参数是过多长时间再重复执行
t.schedule(new MyTimerTask(), new Date(188, 6, 1, 14, 22, 50), 3000);
while (true) {
Thread.sleep(1000);
System.out.println(new Date());
}
}
}
class MyTimerTask extends TimerTask {br/>@Overridepublic void run() {System.out.println("起床背英语单词");}}
欢迎关注本站公众号,获取更多信息