Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT: Timer and Scheduler Classes

Tags:

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 and Timer::scheduleRepeating
  • Scheduler::scheduleDeferred
  • Scheduler::scheduleIncremental
  • IncrementalCommand
  • DeferredCommand

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.

like image 657
IAmYourFaja Avatar asked Sep 11 '12 11:09

IAmYourFaja


1 Answers

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); 

This code will show notificationPanel, and then it will hide it after 10 seconds.

like image 184
Andrei Volgin Avatar answered Sep 20 '22 02:09

Andrei Volgin