定时-TimerTask

别说谁变了你拦得住时间么 提交于 2020-03-18 22:01:26
 
 /**
  * @param args
  * @throws InterruptedException
  */
 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 {
 @Override
 public void run() {
  System.out.println("起床背英语单词");
 }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!