2013-07-17 23 views
0

我在我的应用程序中使用的GWT计时器似乎没有响应对cancel()的调用。GWT Timer.scheduleRepeating在通话取消后继续触发()

我看到新服务器的呼叫被解雇,甚至取消()后到达。

com.google.gwt.user.client.Timer t = new com.google.gwt.user.client.Timer() { 
          @Override 
          public void run() { 
           myService.poll(result.getKey(), new HappyAsyncCallback<JobResult>() { 
            @Override 
            public void onSuccess(JobResult result) { 
             if (result.getUuid() != null && !result.getUuid().isEmpty()) { 
              Window.alert("Done! Cancelling..."); 
              cancel(); 
             } 
            } 
           }); 
          } 
         }; 
         t.scheduleRepeating(5000); 

我读到了这些类似的问题,但是一直不能使用这些问题让我感到不便。

GWT Timer cancel not working

Can't cancel repeat timer in GWT

+1

尝试在alert()之前放置'cancel()'。试着将't'声明为final,并调用't.cancel()'。 –

回答

0

我一直在这里愚弄我自己的应用程序。我们正在服务器上进行非常冗长的批处理过程,在此过程中Timer将触发多次调用poll()。当cancel()方法到达时,这些调用仍然从服务器返回:)感谢您的建议,Manolo。