java怎么再次设置Timer的schedule???

timer已经schedule过了。想在运行过程中更改触发频率。

public class TestTimer {

class MyTimerTask extends TimerTask {
    private int time; //定时执行时间

    public MyTimerTask(){

    }

    public MyTimerTask(int _time){
        this.time = _time;
    }

    @Override
    public void run() {
        System.out.println("time:" + time);
        System.out.println((time==3000) );
        if(time==3000) {
            System.out.println("---------------");
            throw new RuntimeException("异常");
        }
        if(time%6000==0) {
            time = 0;
        }
        System.out.println("下次执行时间" + time);
        new Timer().schedule(new MyTimerTask(time+1000), time);
    }
}
public MyTimerTask init() {
    return new MyTimerTask();
}
public static void main(String[] args) throws Exception {
    new Timer().schedule(new TestTimer().init(), 2000);
    while(true) {
        System.out.println(new Date().getSeconds());
        Thread.sleep(1000);
    }

}

}

不知道能不能满足你的要求

stop掉 重新启动一个。

this.myTask().cancel();//取消一个

看我的博客吧,刚写完
[url]http://chen-yongkai.iteye.com/blog/1673241 [/url]

http://chen-yongkai.iteye.com/blog/1673241