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

发表于:2007-07-01来源:作者:点击数: 标签:
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(
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);


原文转自:http://www.ltesting.net