Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Threading in GWT (Client)

From what I understand, the entire client side of a GWT application is converted to Javascript when you build, therefore I suppose this question is related to both Javascript and the possibilities that GWT offers.

I have a couple of dozen processes that will need to be initiated in my GWT application, each process will then continuously make calls to a server. Does GWT support threading? Does the GWT client side support threading?

EDIT:

This link states:

No JavaScript knowledge required If you’re just a user of the framework,  which I am for the matter of discussion, you do not need to know JavaScript  in order to write dynamic content, be it client-side such as rolling frames,  docking panels or scheduled “multi-threading” tasks, or server-side calls  using XMLHttpRequests (aka AJAX).  

or scheduled “multi-threading” tasks, what does this mean?

like image 300
Federer Avatar asked Apr 07 '10 08:04

Federer


People also ask

What is GWT RPC?

What is GWT RPC? The GWT RPC framework makes it easy for the client and server components of your web application to exchange Java objects over HTTP. The server-side code that gets invoked from the client is often referred to as a service.

What is GWT client?

GWT contains a number of HTTP client classes that simplify making custom HTTP requests to your server and optionally processing a JSON- or XML-formatted response. GWT contains a set of HTTP client classes that allow your application to make generic HTTP requests.


2 Answers

JavaScript doesn't support multithreading. However, GWT has a class to 'simulate' threading, which is not real multithreading, but in most cases does what you need: com.google.gwt.core.client.Scheduler.ScheduledCommand. The technique is based on the timer class, which executes a method after the given time elapses.

For example, when placing the following code in you own code, the scheduleDeferred method will return directly and your code continues after the command, while the execute() method is executed using the timer:

Scheduler.get().scheduleDeferred(new ScheduledCommand() {    public void execute() {       .. code here is executed using the timer technique.    } }); 

You can create a repeating command RepeatingCommand, which can be used to run the command more than once. Start it with Scheduler.get().scheduleIncremental() that will execute the command until the execute method returns false. You can use this to split tasks into sub tasks to get better 'threading' behavior. The Scheduler supports some additional methods to start a scheduled command differently. See the JavaDoc for more details.

Edited and updated with new GWT class instead of the deprecated DeferredCommand.

like image 152
Hilbrand Bouwkamp Avatar answered Sep 22 '22 23:09

Hilbrand Bouwkamp


There is work on Web Workers as part of HTML5 that is implemented in a number of browsers, but not on all (most notably internet explorer). You could use these features where available, but what you should do is look at the javascript programming model.

Javascript generally works asynchronously. Requests are fired off and at some point their answers are received as an event. You can have a large number of pending requests at the same time. This will require a bit of a redesign of your system though.

like image 44
Paul de Vrieze Avatar answered Sep 21 '22 23:09

Paul de Vrieze