java - 取消 GWT 重复计时器

标签 java gwt timer

我有一个场景,我必须每 10 秒刷新一次 GWT 网格才能更新该网格上项目的状态。这是逻辑:

        Timer timer = new Timer(){
            @Override
            public void run(){
               //make server call to update grid
            }
        };

        timer.scheduleRepeating(10000);

我的问题是这样的:当这个网格处于 View 中时,即当演示者被调用时,计时器开始启动,但没有办法停止计时器。导航到不同的 View 不会阻止计时器每 10 秒调用一次服务器。有没有办法在用户导航到另一个 View 时立即停止计时器?应用程序需要不断更新状态,因此必须在网格不再处于 View 中时取消它。

最佳答案

在包含计时器的 Widget 或 Composite( View )中添加:

@Override
protected void onUnload() {
    timer.cancel();
}

This method is called immediately before a widget will be detached from the browser's document.

关于java - 取消 GWT 重复计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51059035/

相关文章:

java - 寻找适用于 Android 的加密/解密 AES 示例

java - GWT.log 抛出错误

java - 不使用 GWTTestCase 对 GWT RequestFactory 服务进行单元测试

timer - 电晕 : timer. 取消()返回 "Attempt to index a nil value"

javascript - 如何在javascript中使用定时器?

java - Android 将单词插入 ArrayList,内存不足

java - <?> 和 <E> 可以互换吗?

Java 互斥体实现

CSS 未在 GWT 中更新

android - 自定义计数定时器