JavaScript does not support multithreading. However, GWT has a class for "simulating" threads, which is not real multithreaded, but in most cases does what you need: com.google.gwt.core.client.Scheduler.ScheduledCommand . This method is based on a timer class that executes the method after a specified time.
For example, when placing the following code in your own code, the scheduleDeferred method will return directly, and your code will continue after the command, and the execute() method will be executed using a timer:
Scheduler.get().scheduleDeferred(new ScheduledCommand() { public void execute() { .. code here is executed using the timer technique. } });
You can create a repeating RepeatingCommand command that can be used to run a command more than once. Run it using Scheduler.get().scheduleIncremental() , which will execute the command until the execute method returns false . You can use this to separate tasks into subtasks to improve the behavior of "threads". Scheduler supports some additional methods for running a scheduled command in different ways. See JavaDoc for more details.
Edited and updated with the new GWT class instead of the deprecated DeferredCommand .
Hilbrand Bouwkamp Apr 7 '10 at 10:18 2010-04-07 10:18
source share