@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.
New contributor
Balaji R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.