Can't cancel repeat timer in GWT

≯℡__Kan透↙ 提交于 2019-12-10 17:37:07

问题


I am trying to schedule a repeating timer in GWT, it will run every one milli second, poll for a certain event, if it is found satisfactory, do something and cancel the timer. I tried doing this:

final Timer t = new Timer() {
    public void run() {
        if (..condition is true, exit) {
            t.cancel();
            doSomething();
        }
    }
}
t.scheduleRepeating(1);

However, I get an error message like the local variable t may not have been initialized. I am putting tis piece of code in the onSuccess clause of a RequestBuilder callback.. How do I achieve this?


回答1:


You cannot access it while intializing itself.

change your code to

 final Timer fgf = new Timer() {

            @Override
            public void run() {
                  cancel();
                  System.out.println();

            }
        };


来源:https://stackoverflow.com/questions/16240695/cant-cancel-repeat-timer-in-gwt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!