schedule
public void schedule(TimerTask task,
                     Date time)
Schedules the specified task for execution at the specified time. If the time is in the past, the task is scheduled for immediate execution. Parameters:
task - task to be scheduled.
time - time at which task is to be executed.我想是那问题
多谢你的贴

解决方案 »

  1.   

    public void schedule(TimerTask task,
                         long delay,
                         long period)你用的方法中的第二个参数是延迟的时间而不是循环处理的时间,可以利用上面的方法实现。
    例子如下
    package testtesttest;import java.util.Timer;
    import java.util.TimerTask;/**
     * Simple demo that uses java.util.Timer to schedule a task to execute
     * once 5 seconds have passed.
     */public class Reminder {
        Timer timer;    public Reminder(int seconds) {
            Timer timer = new Timer();
            timer.schedule(new RemindTask(), seconds*1000,1000);    }    class RemindTask extends TimerTask {
            public void run() {
                System.out.println("Time's up!");        }
        }    public static void main(String args[]) {
            System.out.println("About to schedule task.");
            new Reminder(1);
            System.out.println("Task scheduled.");
        }
    }
      

  2.   

    zzhangwa(化石和石头)
    說的對