Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't cancel repeat timer in GWT

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?

like image 368
SexyBeast Avatar asked Jan 14 '23 13:01

SexyBeast


1 Answers

You cannot access it while intializing itself.

change your code to

 final Timer fgf = new Timer() {

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

            }
        };
like image 147
Suresh Atta Avatar answered Jan 16 '23 03:01

Suresh Atta