1

I have the following codes which is executed every 3 seconds asynchronously

<Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
    @Override
    public boolean  execute() {
        try {
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, "someurl");
            Request response = builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable exception) {                     
                }
                public void onResponseReceived(Request request, Response response) {
                // do some work                 
                }
            });
        } catch (RequestException e) {}
        return true;
    }
}, 3000);  

And the below code which takes long time to proceed.

try {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, "someurl");
    Request response = builder.sendRequest(null, new RequestCallback() {
        public void onError(Request request, Throwable exception) {                     
        }
        public void onResponseReceived(Request request, Response response) {
            // do some work which takes long time to finish             
        }
    });
} catch (RequestException e) {} 

i was expecting the scheduler will make a call in every 3 seconds, but when the other call that takes more time to finish then the call inside scheduler gets blocked which supposed not be as all are asynchronous call.

please let me know if anything wrong in the above scenario.

Danil Gaponov
  • 1,413
  • 13
  • 23
Arabinda Nanda
  • 209
  • 1
  • 4
  • 14

2 Answers2

1

onResponseReceived is executed in the UI thread. Since there is only one UI thread, all events executed by it will be queued and will not overlap.

Dragan Bozanovic
  • 23,102
  • 5
  • 43
  • 110
  • Thanks for your reply. when i say the other call that takes long time to complete that call invocation is not from the scheduler repeating command. Its fine for me when a call inside the scheduler gets long time to complete. But i do not understand why the call inside the scheduleFixedDelay waits for another call invoke to finish which originates from different method like mentioned in above code. – Arabinda Nanda Aug 08 '15 at 04:56
  • You can take a look at HTML5 Workers; I'm not sure what kind of support for them looks like in GWT though. Other options are moving long-running computations to the server, or, to make the page responsive, breaking the computation on the client to multiple steps, where each step is executed in separate UI cycle ([`Scheduler.scheduleDeferred`](http://www.gwtproject.org/javadoc/latest/com/google/gwt/core/client/Scheduler.html#scheduleDeferred(com.google.gwt.core.client.Scheduler.ScheduledCommand)). – Dragan Bozanovic Aug 08 '15 at 07:50
0

This can be caused by connection limit.

There is a limit on simultaneous connections to one domain in web browsers. Connections are queued if you exceed this limit.

Depending on web browser you can have 8-6 or even only 2 connections for IE. See this question.

You can try to increase default limitation and check if this is the issue.

Community
  • 1
  • 1
Adam
  • 5,403
  • 6
  • 31
  • 38