import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class Demo_Timer {
/**
* @param args
* @throws InterruptedException
*/
@SuppressWarnings("deprecation")
public static void main(String[] args) throws InterruptedException {
Timer t = new Timer();
t.schedule(new MyTimerTask(), new Date(116, 5, 24, 22, 12, 30));
//Timer调用schedule方法里的“new MyTimerTask()”是对象,为什么直接调用的是对象里的方法?
while(true) {
Thread.sleep(1000);
System.out.println(new Date());
}
}
}
class MyTimerTask extends TimerTask{
@Override
public void run() {
System.out.println("有梦想,就坚持");
}
}
|
|