Timer: Timer
A tool: Thread task again with its schedule after a background thread execution, enforceable once, executable repeatedly
Which method: Schedule ( TimeTask Task, a Date DATE) is performed only once
schedule (TimeTask task, Date date, time) how much time every execution. Repeat several times
TimeTask class implements Runnable interface, there is an abstract Run () method. Using as parameters to the schedule of TimeTask subclass object ()
import java.util.Date; import java.util.Timer; import java.util.TimerTask; public class demon3_timer { public static void main(String[] args) throws InterruptedException { Timer t1 = new Timer(); t1.schedule(new MyTimerTask(), new Date(119, 7, 14, 23, 59, 30),5000); while (true) { Thread.sleep(1000); System.out.println(new Date()); } } } class MyTimerTask extends TimerTask{ @Override public void run() { System.out.println("该起床了。。。。"); } }