0

This is my servlet

public class TestServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        LogFactory.getLog(getClass()).info(req.getParameter("number"));
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

Now I execute the following js in browser

console.clear();
for (var i = 0; i < 12; i++) {
  $.ajax('/test', {
    data: {
      number: i
    }
  });
}

and results are:

2016-09-15 19:35:26 INFO  TestServlet:17 - 0
2016-09-15 19:35:26 INFO  TestServlet:17 - 2
2016-09-15 19:35:26 INFO  TestServlet:17 - 1
2016-09-15 19:35:26 INFO  TestServlet:17 - 3
2016-09-15 19:35:26 INFO  TestServlet:17 - 4
2016-09-15 19:35:26 INFO  TestServlet:17 - 5
2016-09-15 19:35:28 INFO  TestServlet:17 - 8
2016-09-15 19:35:28 INFO  TestServlet:17 - 6
2016-09-15 19:35:28 INFO  TestServlet:17 - 7
2016-09-15 19:35:28 INFO  TestServlet:17 - 11
2016-09-15 19:35:28 INFO  TestServlet:17 - 10
2016-09-15 19:35:28 INFO  TestServlet:17 - 9

You can see that 6 requests came at 19:35:26 and other 6 at 19:35:28

I use default Tomcat and jquery settings. Why this can happen? Is there any way to configure this?

0

2 Answers 2

1

The browser limits it to 6 ajax requests at a time. You can trick it by separating the endpoints to different subdomains but that gets a little bit out of the question's scope. I don't think there's anything you can do in the browser to change that.

EDIT: See the comments, different ports should work as well

Sign up to request clarification or add additional context in comments.

1 Comment

also different ports!
1

Browser has a limitation on sending ajax requests and use a pool and a queue to send them.

So yes there is no rules. If it important to save the order use async:false but it has very bad impact on user interface.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.