日期:2014-05-17 浏览次数:20691 次
Timer timer=new Timer(); [color=#FF0000]timer.schedule[/color](new TimeTask(),1800000, 1800000);
ScheduledExecutorService scheduler=Executors.newScheduledThreadPool(1); scheduler.scheduleAtFixedRate(new LimitSmorcGatherService(), 1, 2, TimeUnit.SECONDS); LimitSmorcGatherService实现Runnable接口就好了
------解决方案--------------------
import java.util.Timer;
import java.util.TimerTask;
class MyTimerTask extends TimerTask {
public void run() {
System.out.println("Timer task executed.");
}
}
public class MainClass {
public static void main(String args[]) {
MyTimerTask myTask = new MyTimerTask();
Timer myTimer = new Timer();
/*
* Set an initial delay of 1 second, then repeat every half second.
*/
myTimer.schedule(myTask, 1000, 500);
try {
Thread.sleep(5000);
} catch (InterruptedException exc) {
}
myTimer.cancel();
}
}