GWT:计时器和调度程序类 [英] GWT: Timer and Scheduler Classes
问题描述
我已多次阅读此页面,并且只是没有看到 GWT 的 Timer
和 Scheduler
类之间的一些内在差异.我正在寻找以下各项的用例和适用性:
I have read this page over several times, and am just not seeing some of the inherent differences between GWT's Timer
and Scheduler
classes. I'm looking for the use cases and applicability of each of the following:
Timer
、Timer::schedule
和Timer::scheduleRepeating
Scheduler::scheduleDeferred
Scheduler::scheduleIncremental
增量命令
延迟命令
这些似乎或多或少都在做同样的事情,感觉就像你可以用它们来实现相同的目标.这只是 GWT 提供多种方式来做同一件事的方式吗?如果不是,请帮助我了解何时何地适当使用每种方法.
These all appear to be doing the same thing, more or less, and it feels like you can accomplish the same objectives with all of them. Is this just GWT's way a providing multiple ways of doing the same thing? If not, please help me understand when and where each is appropriately used.
推荐答案
使用 Scheduler 当您需要浏览器完成当前正在执行的任何操作,然后再告诉它执行其他操作时.例如:
Use Scheduler when you need a browser to complete whatever it is currently doing before you tell it to do something else. For example:
myDialogBox.show();
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
myTextBox.setFocus();
}
});
在这个例子中,直到浏览器完成对话框的渲染后才会设置焦点,所以你告诉程序等待浏览器准备好.
In this example, focus will not be set until the browser completes rendering of the dialog, so you tell the program to wait until the browser is ready.
使用计时器,如果您希望在指定的时间段后执行某些操作.例如:
Use Timer if you want some action to happen after a specified period of time. For example:
notificationPanel.show();
Timer timer = new Timer() {
@Override
public void run() {
notificationPanel.hide();
}
};
timer.schedule(10000);
这段代码会显示notificationPanel,10秒后隐藏.
This code will show notificationPanel, and then it will hide it after 10 seconds.
这篇关于GWT:计时器和调度程序类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!