0
@RestController public class HomeController { @GetMapping("/") public String greet() throws InterruptedException { System.out.println(Thread.currentThread().getName()); Thread.sleep(4000); return "<h1>Hello from Spring boot app<h1>"; } } 

In a browser open 2 tabs. Send first request in one tab and immediately in second tab seond other request. The first request is served in 4 seconds, however 2nd request is taking around 7 seconds. Why is this? Servlet container is thread per request right, then if each request is spawned innew thread each request should ideally be served in 4 seconds only. Can anyone explain what's happening here.

7
  • Which servlet container are you using? Show us your boot config. Provide a minimal reproducible example. Commented Jul 8, 2024 at 14:19
  • 1
    Browsers have limits on how many requests go to 1 URL concurrently as well, it is not only the server that plays a role. Commented Jul 8, 2024 at 14:21
  • Its just a starter spring boot application, no other code than this controller. So by default it is using the tomcat container. Commented Jul 8, 2024 at 14:32
  • Considering "Browsers have limits on how many requests go to 1 URL concurrently as well", i tried sending the request from different browser, one from edge and one from chrome, now i can see that both are served in 4 seconds. Is there any settings in the browser where we can set max concurrent req to same server ? Commented Jul 8, 2024 at 14:39
  • Why are adding a sleep to your code? Are you trying to simulate something? Provide context. Commented Jul 8, 2024 at 15:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.