Timer Task 的简单范例(相当触发器,转自Sun)

Scheduling a Timer Task to Run at a Certain Time
==============================================
Date timeToRun =
   new Date(System.currentTimeMillis()+
   numberOfMillisecondsInTheFuture);
Timer timer = new Timer();
     
timer.schedule(new TimerTask() {
         public void run() {
             // Task here
         }
     }, timeToRun);
============================================

Scheduling a Timer Task to Run Repeatedly

=============================================
// delay for 5 sec.

int delay = 5000;   

// repeat every sec.

int period = 1000;  
Timer timer = new Timer();
     
timer.scheduleAtFixedRate(new TimerTask() {
         public void run() {
             // Task here
         }
}, delay, period);

【问题提问、论坛交流】编辑:xker.com