Arabinda Nanda
Arabinda Nanda

Reputation: 209

does asynchronous call in GWT get blocked due to another asynchronous call which taking long time to finish

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.

Upvotes: 1

Views: 221

Answers (2)

Adam
Adam

Reputation: 5599

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.

Upvotes: 0

Dragan Bozanovic
Dragan Bozanovic

Reputation: 23552

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.

Upvotes: 1

Related Questions